Visual Studio C/C++ Array Size Unhandled exception Stack overflow

6

Possible Duplicate:
What is a stack overflow error?

It just happens when I declare large arrays with the size of 4096*1024

First-chance exception at 0x01382e97 in nsfclient.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x01382e97 in nsfclient.exe: 0xC00000FD: Stack overflow.

What should I do to be able to declare big arrays in Visual Studio?

c
visual-studio-2010
asked on Stack Overflow Dec 29, 2012 by bit8bug • edited Jan 29, 2019 by Raymond Peng

2 Answers

10

You should explicitly increase the stack size to be able to store bigger arrays on the stack. As far as I remember this is done using the /F option.

Another option would be to use dynamic arrays(allocated using malloc or new).

EDIT(thanks to Jefrrey Theobald): you will also have to increase the stack size in the linker, which is done using the /stack option. This option can also be set by right-click on the project->properties->linker->system and setting stack commit and stack reserve size. enter image description here

answered on Stack Overflow Dec 29, 2012 by Ivaylo Strandjev • edited Jun 1, 2017 by Mona Jalal
4

You don't show any code but I presume you're declaring your array on the stack. Try declaring it on the heap (using malloc) instead. Make sure to free it later.

char* bigArray = malloc(LARGE_SIZE);
/* use bigArray */
free(bigArray);
answered on Stack Overflow Dec 29, 2012 by simonc

User contributions licensed under CC BY-SA 3.0