Memory Layout
Memory Layout
That's how VM works. For the most part, each process's VM space is laid out in a similar and predictable manner:
| High Address | Args and env vars | Command line arguments and environment variables |
| Stack | V |
||
Unused memory |
||
| ^ | Heap |
||
| Uninitialized Data Segment (bss) | Initialized to zero by exec. | |
| Initialized Data Segment | Read from the program file by exec. | |
| Low Address | Text Segment | Read from the program file by exec. |
- Text Segment: The text segment contains the actual code to be executed. It's usually sharable, so multiple instances of a program can share the text segment to lower memory requirements. This segment is usually marked read-only so a program can't modify its own instructions.
- Initialized Data Segment: This segment contains global variables which are initialized by the programmer.
- Uninitialized Data Segment: Also named "bss" (block started by symbol) which was an operator used by an old assembler. This segment contains uninitialized global variables. All variables in this segment are initialized to 0 or NULL pointers before the program begins to execute.
- The stack: The stack is a collection of stack frames which will be described in the next section. When a new frame needs to be added (as a result of a newly called function), the stack grows downward.
- The heap: Most dynamic memory, whether requested via C's malloc() and friends or C++'s new is doled out to the program from the heap. The C library also gets dynamic memory for its own personal workspace from the heap as well. As more memory is requested "on the fly", the heap grows upward.

浙公网安备 33010602011771号