To set the stack space for C + + programs to solve stack overflow problem when the static data volume of the program is large, sometimes stack overflow problem, often the program has not run the algorithm, then down, such as when you create a large array of classes (or data), the stack will overflow. This is because the stack space that the system allocates to the program is too small. One way to do this is not to statically allocate it, create it dynamically with new, allocate it from the heap, the heap is large enough, but remember to write the destructor, delete the heap space you requested. In fact, this is also very convenient, the end of the class will automatically call the destructor to free space. It is important to develop a good habit of "not defining large arrays/large objects on the stack", otherwise the large stacks will be blown up. Of course, if you do not like New,delete, or static allocation (after all, static allocation has a lot of benefits), you can change the default stack space to solve. Link's/stack option/stack:reserve[,commit] Reserve: Stack total size commit: The actual amount of memory provided by the system at the start of the program defaults: the 1m,8k parameter is 0 to take the default value today in Vc. NET run the cluster program, always say Stack OverFlow, later found that the stack space is too small. The amount of data stored on only 100 pages is relatively large. The size of the stack has been set to: Stack reserve size: 100000000; The stack commit size is: 100000000; There's no problem. Settings: Project---Properties---linker--system-> stack reserve size/Stack commit size problem answer:
Method One: STACKSIZE define the. def file
Syntax: STACKSIZE Reserve[,commit] Reserve: The size of the stack; commit: optional, related to the operating system, only allocates the size of the physical memory once on NT
Method Two: Set/stack
Open the project and proceed to the following menu: Project->setting->link, select output in category, then set the maximum and commit of the stack in the reserve.
Note: The default value of the reserve is 1MB, the minimum value is 4byte;commit is kept in the virtual memory of the page file, it is set larger will make the stack open a larger value, may increase the memory overhead and startup time
Set up stack space for C + + programs to resolve stack overflow issues