BSS segment: A BSS segment (BSS segment) is usually used to store data segments in a program : data segment usually refers to a chunk of memory that is used to hold the initialized global variables in the program . The data segment belongs to static memory allocation .
Data segment: data segment usually refers to an area of memory that is used to hold the initialized global variables in the program . The data segment belongs to static memory allocation .
Code Snippets: code segment/text segment usually refers to an area of memory that is used to store program execution code. The size of this area is determined before the program runs, and the memory area is usually read-only, and some schemas allow the code snippet to be writable, which allows the program to be modified. in a code snippet, it is also possible to include some read-only constant variables, such as String constants .
Heap: a heap is a memory segment that is allocated dynamically during a process run and is not fixed in size and can be dynamically expanded or scaled down. When a process calls a function such as malloc to allocate memory, the newly allocated memory is dynamically added to the heap (heap is expanded), and freed memory is removed from the heap when memory is freed (heap is scaled down).
Stack: Stacks are also called stacks, which are local variables that are temporarily created by the user's program , that is, the variables defined in the parentheses "{}" (but not the variables that are static declarations, static means that the variables are stored in the data segment). In addition, when a function is called, its arguments are also pressed into the process stack that initiates the call, and the return value of the function is stored back to the stack when the call ends . Due to the advanced post-out features of the stack, the stack is particularly handy for saving/recovering call sites. In this sense, we can think of the stack as a memory area where temporary data is stored and exchanged.
It is assigned by the operating system, and memory requests and recoveries are managed by the OS.
The global uninitialized variable exists in the. BSS segment, which is represented by a placeholder; the global initialized variable is stored in the. Data segment, and the automatic variables within the function allocate space on the stack: BSS is not occupying executable space and its contents are initialized by the operating system (0) , while. Data needs to be occupied, and its contents are initialized by the program, resulting in this situation.
A BSS segment (data that is not manually initialized) does not allocate space to the data for that segment, but only the amount of space required to record the data.
Data (data that has been manually initialized) segments are allocated space and the data is saved in the destination file. The data segment contains the initialized global variables and their values. The size of the BSS section is obtained from the executable file, and then the linker gets a block of memory of that size, immediately following the data segment. When this memory area enters the program's address space, it is all zeroed out. The entire segment that contains the data segment and the BSS segment is often referred to as the data area.
5 large segments of the Linux process