个人比较懒,就不翻译了,直接上英文,来自于《Advanced Programming In The Unix Environment》
1. Text segment, consisting of the machine instructions that the CPU executes. Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.
2. Initialized data segment, usually called simply the data segment, containing variables that are specifically initialized in the program. For example, the C
declaration
int maxcount = 99;
appearing outside any function causes this variable to be stored in the initialized data segment with its initial value.
3. Uninitialized data segment, often called the ‘‘bss’’ segment, named after an ancient assembler operator that stood for ‘‘block started by symbol.’’ Data in this segment is initialized by the kernel to arithmetic 0 or null pointers before the program starts executing. The C declaration
long sum[1000];
appearing outside any function causes this variable to be stored in the uninitialized data segment.
4. Stack, where automatic variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables. This is how recursive functions in C can work. Each time a recursive function calls itself, a new stack frame is used, so one set of variables doesn’t interfere with the variables from another instance of the function.
5. Heap, where dynamic memory allocation usually takes place. Historically, the heap has been located between the uninitialized data and the stack.
本文深入探讨了Unix环境下程序运行时涉及的主要内存区域:文本段、初始化数据段、未初始化数据段以及堆栈和堆。通过具体实例解释了每个区域的功能和用途,帮助开发者更好地理解内存管理和程序执行过程。
416

被折叠的 条评论
为什么被折叠?



