A c program mainly includes the following parts in the memory space:
1. Code segment
2. Data Segment
3. Stack
4. Heap
Code access code segments. data segments are static and global variables. function parameters and local variables are stored in the stack. The heap stores the allocated areas of malloc.
Inside the stack is a stack structure. When pushing something in the stack, small data is the basic data such as shaping and floating point data. However, the stack has a larger unit, that is, the stack frame. A function usually corresponds to a stack frame, and the first instruction address that is executed after the function is entered in sequence in the stack frame, parameters (usually from right to left), local variables. There are two stack allocation methods: static allocation and compiler allocation. The second is dynamic allocation. Calling malloca for allocation is different from the heap for dynamic allocation. The memory allocated on the stack does not need to be recycled by the programmer. When the program returns, it will be recycled.
Heap is dynamically allocated. In theory, heap space can be very large and full of space. It is the interface provided by C/C ++ library functions, the operating system is not as native as stack, So heap is slower than stack, and the operating system has a dedicated stack register.
Stack is a continuous area with a fixed size. It is determined during the compilation period. In Windows, the default value is 2 MB, while heap is a non-sequential area. When you create an address, access a free list executed by the operating system, select a suitable region based on the algorithm, and then allocate the program, record it to the heap, and record the size on this terminal, when free is used, the size can be released based on the address.
FFFF
Heap
----
Stack
0000
Heap growth direction is towards address growth direction, stack is toward address reduction direction
MATERIALS:
Http://blog.csdn.net/rujielaisusan/article/details/4622197
Http://blog.csdn.net/yeyuangen/article/details/6766567
Memory space of the C program