C++ Stack Overflow

Soldato
Joined
22 Oct 2005
Posts
2,884
Location
Moving...
I've got some code in C++, I have a pointer to some data atm but I want to change it to an array so it's easier to debug. However when I try to change it I get a stack overflow error:

Unhandled exception at 0x00411277 in driver.exe: 0xC00000FD: Stack overflow.

This gets thrown up when I define my array (int data[2359296]), however if I make the array smaller it works, does this just mean I don't have enough space? I do most of my work in Java and have much larger arrays than this and I'm sure I've used larger arrays in C before.

Is this the reason or am I missing something?
Thanks.
 
I'm guessing the array you are declaring is a local variable within a method, in which case it is allocated from the stack. The size of this array is then exceeding the default stack size configured in your compiler. What compiler/platform are you using? You may need to examine the compiler options to increase the stack size for your program, or consider using a smaller array :)
 
If the problem is that you cant see your dynamic array in the debugger then try to fix that issue (instead of increasing your programs stack size :/ -- dont do this).

Most debuggers allow you to view pointers as arrays of objects (read the documentation) e.g. visual studio you can do mypointer,10 in the watch window to turn mypointer into an array of ten elements.

Alternatively you could do something like:

Code:
int (&myarray)[10] = (int (&)[10])*mypointer;

to declare a reference to an array (should be viewable in the debugger).
 
Good advice - either that or just allocating the array on the heap would be a much better solution rather than fiddling with the stack size.
 
Back
Top Bottom