I have a program that does recursive calls for 2 billion times and the stack overflow. I make changes, and then it still need 40K recursive calls. So I need probably several MB stack memory. I heard the stack size is default to 1MB. I tried search online. Some one said to go properties ->linker .........in visual studio, but I cannot find it.
Does anybody knows how to increase it? Also I am wondering if I can set it somewhere in my C# program?
P.S. I am using 32-bit winXP and 64bit win7.
You can do this by using the "ulimit -s" command in linux which will set the stack size for all process executed under that shell. Incase of windows, the same can be done in VC6 for that project by setting the stack size in Project Properties->link options->output->stack allocations->reserve.
You may need to increase the stack size if your program gets stack-overflow messages at runtime. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations).
Today's PCs have a large amount of physical RAM but still, the stack size of C# is only 1 MB for 32-bit processes and 4 MB for 64-bit processes (Stack capacity in C#).
In Microsoft Windows 2000, if the Microsoft ASP.NET Worker Process (ASPNet_wp.exe) creates a thread, the maximum stack size of the thread is 1 MB. In Windows Server 2008 and higher, the maximum stack size of a thread running on 32-bit version of IIS is 256 KB, and on an x64 server is 512 KB.
The space between /F and number is optional. You may need to increase the stack size if your program gets stack-overflow messages at runtime. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations).
You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations). Using EDITBIN on the EXE file. For more information, see EDITBIN reference. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
The linker rounds up the specified value to the nearest 4 bytes. The space between /F and number is optional. You may need to increase the stack size if your program gets stack-overflow messages. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK.
The stack size in bytes. Without this option, the stack size defaults to 1 MB. The number argument can be in decimal or C-language notation. The argument can range from 1 to the maximum stack size accepted by the linker. The linker rounds up the specified value to the nearest multiple of 4 bytes.
The easiest way to set the stack size from .NET 2.0 and Win XP onwards is to spawn a new thread with the stack size you'd like:-
using System.Threading; Thread T = new Thread(threadDelegate, stackSizeInBytes); T.Start();
To change the stack size of the entire program you'd have to use editbin:-
EDITBIN.EXE /STACK:<stacksize> file.exe
There is no compiler option to do it. You can edit it after the fact using editbin /stack, or create a separate thread for your algorithm, and specify a larger stack size in the Thread constructor.
That being said, you may want to flatten your recursive function... If you're having stack overflows now, it's tough to know that any stack size will be appropriate in the long term. This is just a band-aid solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With