when i try to create a 2d array of 512 by 512 i get an exception( Unhandled exception at 0x00A916D7 in ConsoleApplication3.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00752000).
int main()
{
int a[512][512];
return 0;
}
when i try to create a 2d array of 512 by 512 i get an exception( Unhandled exception at 0x00A916D7 in ConsoleApplication3.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00752000).
int main()
{
int a[512][512];
return 0;
}
Window's default stack size is 1MB, and the size of int (4 bytes) * 512 * 512 = 1MB.
When you declare an array inline, such as the line int a[512][512]
, this is done using the stack. Since there will be a few things already on the stack, that's why you're hitting a stack overflow (as Mitch pointed out) after "only" 508x508 (don't depend on that many!).
Instead of allocating the array of arrays on the stack, use new
/malloc
to allocate it on the heap. Depending on exactly what you're trying to do, arrays might not even be the right data structure.