I'm looking for a way to increase the stack size, for my program to run, the reason is that I've a recursive call causing a stack overflow. Is there anyway I can change the default stack size?
Asked
Active
Viewed 3,209 times
1
-
2Maybe if you tell us the compiler? – crashmstr Apr 08 '13 at 19:57
-
see this solution? http://stackoverflow.com/questions/2275550/change-stack-size-for-a-c-application-in-linux-during-compilation-with-gnu-com – taocp Apr 08 '13 at 19:58
-
4You can on most platforms, but I predict it won't solve your problem. If you overflow the stack, you either have unlimited recursion or at least use asymptotically too much stack space, so even if you increase the stack size, you can only run your program slightly longer/on slightly larger data sets. Better fix your algorithm instead. – Apr 08 '13 at 19:58
-
@delnan: I guess it depends... AIX 32bits allocates 96kb for the stack of each thread created with `pthread_create`. It is not that hard to push beyond 96k... – David Rodríguez - dribeas Apr 08 '13 at 20:31
-
better suggestion as above - to fix the algorithm. However, the other part is, that the "stack" size of the system would need to be increased and is not specific to the program. The increased stack size allowed on the system then would allow the program to execute (if the code is really blocked by the stack size limitations). For that @jman answer below suffices for setting and validating. – parasrish Dec 03 '18 at 03:12
3 Answers
2
If its a *NIX, use
ulimit -s <number_in_kb>
You'd set that in your environment before running your program. You can also set it programatically as described in this answer.
You can view the current value by running ulimit -a
.
1
Use editbin to change the stack size of the program:
EDITBIN.EXE /STACK: yourprogram.exe
0
Its compiler dependent. In Visual studio stacksize is fixed to 1 MB. You can increase it using /STACK linker option.

shivakumar
- 3,297
- 19
- 28