Memory space of the C program

Source: Internet
Author: User

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

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.