I am trying to run a simple code that will create a 2D array. At first I declared the array normally, but it got an abnormal termination.
In the task manager the program typically grew to a size of 0.4 MB and was terminated. So, after some research, I discovered the heap and consequently tried to store there. This time it took almost 3 GB and my OS restarted due to low memory.
int main()
{
for(int i=0;i<1000;i++) // outer loop to create 1000 instances
{
int** c = new int*[3000]; // creating 2D array of size 3000*3000
int** b = new int*[3000];
for(int z=0;z<3000;z++)
{
c[z] = new int[3000];
b[z] = new int[3000];
}
}
return 0;
}
So, as far as I can tell, the maximum size of c is [3000][3000] = 36*10^6 B = 36 MB
Now I have 4GB of RAM, so this seems quite unfair.
Anyway I understand that C++ does not have auto garbage collection; that's why the remains are left out. However, I need this array structure for computation. How can I get it to use more of the available memory?