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?

Raymond
  • 396
  • 4
  • 21
bit8bug
  • 97
  • 1
  • 1
  • 12

2 Answers2

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

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
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);
simonc
  • 41,632
  • 12
  • 85
  • 103
  • what is telling you that malloc uses the stack ? The standard doesn't specify that, it's a misleading information. – user1824407 Dec 29 '12 at 11:03
  • 2
    I think you've misunderstood. I'm suggesting that the OP currently has a large array on the stack and should move it to be dynamically allocated on the heap instead, by using malloc to allocate the array memory. i.e. Use of malloc will move the array to the heap. – simonc Dec 29 '12 at 11:08
  • ant this is also false, AFAIK there is no reference to both stack and heap in the entire C++ standard, can you show a reference to a description of malloc that does what you are writing? – user1824407 Dec 29 '12 at 11:10
  • 3
    @user1824407 First, this is about C, not about C++. Secondly: the question is not about the standard but about a specific compiler. – Sjoerd Dec 29 '12 at 11:26
  • 3
    The question is tagged visual-studio-2010 which is a strong hint that the OP is running on Windows. It doesn't seem unreasonable to assume that all versions of Windows use a heap for dynamic allocation (its what the [MSDN docs](http://msdn.microsoft.com/en-us/library/6ewkz86d(v=vs.80).aspx) hint at and this [previous SO question](http://stackoverflow.com/questions/5728077/malloc-returns-memory-or-virtual-adress-space) agrees as well). – simonc Dec 29 '12 at 11:26
  • @Sjoerd i personally do not agree with a reply that doesn't specify that this is a compiler and platform specific behaviour, even if the question is tagged with a VS signature the problem is that this is a misleading answer and for someone that doesn't know the standard it's not that trivial to make a distinction and knowing where the standard ends and where the Microsoft compiler begins. – user1824407 Dec 29 '12 at 11:34