Hey, i just got alil problem. Im trying to create a 2d array with a size of [1000][1000]...

double variable[1000][1000] = { 0 };

its compiles fine but when i run the program, it just crashes...is the array too big?? the maximum i can get is [300][300]...any ideas??

> double variable[1000][1000] = { 0 };
In other words, about 8MB in size.
You're basically blowing away the stack, which depending on your machine could be as little as say 16K in size.

Depending on your compiler, you can specify the initial stack size as being something else.

Since 300*300*8 is about .75 Meg, I'd guess your stack size defaults to 1MB.

1. Make it global - move the array outside of the function it is in.

2. Make it static, as in static double variable[1000][1000] = { 0 }; 3. Allocate it dynamically.

double (*variable)[1000] = new double[1000][1000]; // c++ way
double (*variable)[1000] = malloc ( 1000 * sizeof(*variable) );  // C way

Hey, i just got alil problem. Im trying to create a 2d array with a size of [1000][1000]...

double variable[1000][1000] = { 0 };

its compiles fine but when i run the program, it just crashes...is the array too big?? the maximum i can get is [300][300]...any ideas??

there is a limit of array allocation, the size u are trying causes stack overflow of the function, beacuse ur array can't fit into the memory allocated to th function stack.
there is a limit of 8MB on the maximum size of objects, due to internal compiler implementation limits.
You should use malloc() to create large arrays instead.

This article has been dead for over six months. Start a new discussion instead.