C Process Memory Layout description

Source: Internet
Author: User

Text: Code snippet. The entire code (instruction) of the stored program, derived from the code portion of the binary executable, is placed in the binary file at compile time.

Initialized data (referred to as data segment) and uninitialized (BSS) Form a segment. Where the data segment holds the initialized global variable and the initialized static local variable, derived from the part of the binary executable, which is already placed in the binary file at compile time, the BSS segment holds uninitialized global variables and uninitialized static local variables. The content does not originate from the data part of the binary executable (that is, the data part of the binary executable does not have an uninitialized global variable and the static local variable is uninitialized). According to the C language standard, their initial value must be 0, so the BSS section is stored in all 0. The work of BSS Chingqing 0 is done by the system after the binary file is loaded, and the system performs this clear 0 operation is a piece of code completed by the kernel (exec system call). As to where exec begins to clear 0 from memory-and to clear 0 less space-it is determined by the information recorded in the binary executable (that is, the size of the text, data, BSS section is recorded in the binary file)

malloc allocates space from the heap.

The stack (stack) holds dynamic local variables. That is, when the child function is called, the system allocates space from the stack to the dynamic local variable of the child function (note: The stack is extended to the memory low address), and when the child function returns, the stack of the system extends to the memory high address, which is equivalent to freeing the memory space of the dynamic local variable of the child function. Assuming that the main function calls sub-function B immediately after calling the child function A, then the dynamic local variables of sub-function B will overwrite the storage space of the dynamic local variables of the original sub-function A, which is the fundamental physical reason that the sub-functions cannot access each other's dynamic local variables.

The top end of the memory is the command line arguments and environment variables, the command line parameters and environment variables are placed in the specified location this operation is a piece of code with the OS (the Exec system call) after loading the binaries into memory, before starting to run the program to complete.

From "Linux C language application Programming"

C Process Memory Layout description

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.