"C + +" modifies the default stack size for VS2013 __c++

Source: Internet
Author: User

Before we explain why, let's take a look at the memory that a program compiled by C + + + is divided into several parts:

1, Stack area (stack segment): The compiler automatically assigns release, the value of the parameters of the function, local variables, and so on. Under Windows, a stack is a data structure that is extended to a low address and is a contiguous area of memory. The address of the top of the stack and the maximum capacity of the stack are predetermined by the system, in Windows, the size of the stack is 2M (also some 1M, in short, a compile-time constant), if the requested space over the stack of the remaining space, will prompt overflow. Therefore, the space can be obtained from the stack is small.

2, Heap area (heap segment): Generally by the programmer assigned to release, if the programmer does not release, the program at the end of the system may be recycled. It is different from the heap in the data structure. A heap is a data structure that is extended to a high address and is a contiguous area of memory. This is because the system is used to store the free memory address of the list, nature is discontinuous, and the link list of the traversal direction is from the low address to the high address. The size of the heap is limited by the virtual memory available in the computer system. This shows that the heap to obtain a more flexible space, but also relatively large.

3, the global area (static area) (data segment): global variable and static variable storage area is together, after the program is released by the system. The size of the data area is limited by the system and is generally large.

4, literal constant area: the constant string is placed here, after the program is released by the system.

5. Program code area: the binary code that holds the function body.

To sum up, the local variable space is very small, we open a a[1000000] will lead to stack overflow, and the global variable space in the win 32bit can reach 4GB, so will not overflow.

How 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 method of setting the stack size in VS2010 is:

1. Select the Project-> property.
2). Select the linker.
3. Select "System".
4. The size of a stack in stack reserve size, for example: 32768.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.