Before we explain why, let's take a look at a few parts of the memory that a program compiled by C + + uses is divided into:
1, Stack segment: The compiler automatically allocates the release, the value of the parameter that holds the function, the value of the local variable, and so on. Under Windows, the stack is the data structure that extends to the low address, which is a contiguous area of memory. This sentence means that the top of the stack address and the maximum capacity of the stack is the system pre-defined, in Windows, the size of the stack is 2M (also some 1M, in short, a compile-time determination of the constant), if the requested space exceeds the stack's remaining space, will prompt overflow. Therefore, the space available from the stack is small.
2, Heap area (heap segment): Generally by the programmer allocation release, if the programmer does not release, the program ends may be collected by the system. It is different from the heap in the data structure. A heap is a data structure that extends to a high address and is a discontinuous area of memory. This is because the system is stored with a linked list of free memory address, is naturally discontinuous, and the chain of the list of traversal direction is from the low address to high address. The size of the heap is limited by the valid virtual memory in the computer system. Thus, the space of the heap is more flexible and relatively large.
3. Global zone (static zone) (data segment): The storage area of global variables and static variables is together and released by the system after the program ends. The size of the data area is limited by the system and is generally large.
4, text constant area: the constant string is placed here, the program is released after the end of the system.
5, program code area: the binary code that holds the function body.
In summary, the local variable space is very small, we open a a[1000000] will cause the stack overflow, and the global variable space in the win 32bit can reach 4GB, so does not overflow.
Ways to modify the stack size in VC6.0:
1). Select "Project->setting".
2). Select "Link".
3. Select "Output" in "Category".
4. The size of the stack in "reserve:" in "Stack allocations", for example: 32768
The way to set the stack size in VS2010 is:
1). Select Project, Properties.
2). SELECT Linker.
3. Select "System".
4. In the stack reserve size, the size of the stack, for example: 32768.
Visual Studio declares that the array is too large to cause a stack overflow