Open big question about the C language array overflow

C language occupied memory can be divided into five zones:

           ① code area (Text Segment): easy to understand, is to place the code compiled after the binary machine code.

           ② heap (Heap): used for dynamic memory allocation. General allocation and release by the programmer, if the programmer does not release, it is possible to recover the operating system by the end of the program. (In fact, malloc () function can control memory area)

           ③ stack area (Stack): automatically allocated by the compiler and releasing, generally used to store local variables, function parameters (the focus draw knock blackboard!).

           ④ global initialization data area / static data area (Data Segment): As the name suggests, is a place to store global variables and static variables. This area is shared throughout the process.

           ⑤ uninitialized data area (BSS): changed at run time. Change the value (initialization) when it is based on a global variable or a local variable, they go into the area. Otherwise it will continue to stay inside BSS madding crowd. (A little later we will use experiments to prove its existence and experience.)

 

Under Windows, the allowed space Data Segment depends on the size of the remaining memory, that is, if the computer's memory, then the remaining 8G, int type of two-dimensional array can even be open to the size of 46340 * 46340;

      

The space Stack only 2M! ! I.e. 2 * 1024 * 1024 = 2097152 bytes, the local variable space at most let go the 524288 type int !

 

But I want to open a large array of how to do locally? Very simple, it will go into the Data Segment:

#include<iostream>
using namespace std;
int main()
{
    static int dis[8000][8000];
    //代码
}

 

Reference:  https://blog.csdn.net/qq_21882325/article/details/65445810

 

 

Guess you like

Origin www.cnblogs.com/kazama/p/11917023.html