Visual Studio declares that the array is too large to cause a stack overflow

Source: Internet
Author: User

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

Related Article

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.