process virtual memory

Linux virtual memory system

Linux maintains a separate address space for each process (so each process thinks it owns all memory space exclusively). The memory space distribution of the process is shown in the figure.

  1. text segment, code segment
  2. The data segment stores the data that has been determined during the compilation phase, including global variables and static variables assigned initial values, as well as constants
  3. The bss segment stores global variables or static variables that are not initialized or initialized to 0 in the program. The bss segment is initialized (cleared) by the system when the program is loaded into memory (the data segment and the bss segment are distinguished here, text and data. The data in the segment is stored in the executable file, which is directly loaded by the system from the executable file, while the bss segment is only marked in the executable file, occupying a place, indicating that there is such a variable, when the program is loaded into memory In the middle, the system will clear the bss segment)
  4. The user stack is used to store data such as local variables. It is different from the heap and does not require user management, and is automatically allocated and released.
  5. The memory allocated by the heap calling malloc needs to be released through free, and the user manages it manually

The above storage areas determine several memory allocation methods:

  1. Static memory allocation, which has been determined at compile time, exists during the entire runtime of the program, including the data segment and the bss segment
  2. stack, the system automatically manages
  3. Heap, programmers manually apply and release

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324931975&siteId=291194637