How to overcome Stack Size issue with Visual Studio (running C codes with big array)

It seems that the reason behind this is the stack overflow. The issue can be resolved by increasing the stack size.
In visual studio you can do this by using /STACK:reserve[,commit]. Read the MSDN article.


For more detailed explanation:

Under Windows platforms, the stack size information is contained in the executable files. It can be set during compilation in Visual studio C++.
Alternatively, Microsoft provides a program editbin.exe which can change the
executable files directly. Here are more details:

Windows (during compilation):

  1. Select Project->Setting.
  2. Select Link page.
  3. Select Category to Output.
  4. Type your preferred stack size in Reserve: field under Stack
    allocations
    . eg, 32768 in decimal or 0x20000 in hexadecimal.

Windows (to modify the executable file):

There are two programs included in Microsoft Visual Studio, dumpbin.exe and editbin.exe. Run dumpbin /headers executable_file, and you can see the size of stack reserve information in optional header values. Run editbin /STACK:size to change the default stack size.

Leave a Comment