mathsprogrammer
August 7th, 2004, 06:08 AM
I have written a c++ program in visual studio. Inside the program I make reference to the System.Random() class in .NET. My program contains a very computationally intensive loop that loops 300000 times and inside the loop certain fuctions are performed over and over again.
My problem is that on running the program, it uses up to 250MB of memory. This is obviously a problem as it really needs to run for much longer (shorter runs use up much less memory).
I was thinking that my variables and arrays that I define in a function (one that is referred to 28 time inside the large loop - so runs 300000*28 times) are redefined every time the function runs and thus are taking up a different place in memory every time.
I do, however, define my arrays using pointers as follows:
int *consecutive;
consecutive = new int[Planning_Horizon_Length];
and then run
delete[] consecutive;
at the end of the function. Would I be right in saying that this is performing memory clean ups on it?
Obviously, any variables defined in these functions are defined directly as
int i, j;
Could this be where my problem is?
Lastly, I have a 3 dimensional global array (defined using pointers again) that these functions update. Is there a special way to update this array or will:
for (k1 = 0; k1 < Planning_Horizon_Length; k1++)
{
for (k2 = 0; k2 < Number_Of_Shifts; k2++)
{
X_temp[k1][k2] = X[i][k1][k2];
X_temp1[k1][k2] = X[j][k1][k2];
}
}
work fine?
Any help would be appreciated.
My problem is that on running the program, it uses up to 250MB of memory. This is obviously a problem as it really needs to run for much longer (shorter runs use up much less memory).
I was thinking that my variables and arrays that I define in a function (one that is referred to 28 time inside the large loop - so runs 300000*28 times) are redefined every time the function runs and thus are taking up a different place in memory every time.
I do, however, define my arrays using pointers as follows:
int *consecutive;
consecutive = new int[Planning_Horizon_Length];
and then run
delete[] consecutive;
at the end of the function. Would I be right in saying that this is performing memory clean ups on it?
Obviously, any variables defined in these functions are defined directly as
int i, j;
Could this be where my problem is?
Lastly, I have a 3 dimensional global array (defined using pointers again) that these functions update. Is there a special way to update this array or will:
for (k1 = 0; k1 < Planning_Horizon_Length; k1++)
{
for (k2 = 0; k2 < Number_Of_Shifts; k2++)
{
X_temp[k1][k2] = X[i][k1][k2];
X_temp1[k1][k2] = X[j][k1][k2];
}
}
work fine?
Any help would be appreciated.