Efficient coding with memory management

I’ve switched recently from matlab to c++ in order to run simulations faster, however it still runs slow. I’m pretty positive that there is much to improve in terms of memory usage.

Consider the following code, it shows an example of two array/vector declaration, that I use in a simulation.

One with known fixed length (array01) and another with unknown length (array02) that changes during the run.

The question here is what is the best/proper/efficient way of declaring variables ( for both array types) in terms of memory usage and performance.

# include <iostream>
# include <vector>
# include <ctime>
# include <algorithm>
using namespace std;

const int n = 1000;
const int m= 100000;
int main()
{
    srand((unsigned)time(NULL));
    vector <double> array02;
    vector <vector<double>> Array01(n,m);
    for (unsigned int i=0; i<n; i++)
    {
        for (unsigned int j=0; j<m;j++)
        {
             array02.clear();
             rr = rand() % 10;
             for (unsigned int l = 0 ; l<rr <l++)
             {
                  array02.pushback(l);
             }
             // perform some calculation with array01 and array02
         }           
     }
}

read more

Exit program and open file

Hello I am stuck in a situation where I need to run a command after my program exits.

Reason :

MyApp1.exe needs to be updated to a new version MyApp2.exe. So, MyApp1.exe should be terminated before I start MyApp2.exe, else inno setup will not let me install the new version as the old version is still running.

File.open("MyApp2.exe", "wb") do |saved_file| open("http://example.com/MyApp2.exe", "rb") do |read_file| saved_file.write(read_file.read) end end `start "" "MyApp2.exe"` exit

Now the start command is before exit, as I want to start the new downloaded MyApp2.exe, but I would like to exit first and then start the installer.

Please help

Exit program and open file