Next: Examples&Exercises:
Up: OPERATING SYSTEMS LABORATORY VIII
Previous: Examples&Exercises:
Contents
- Compile and run the code.
- Analyze the code and output.
Figure 2:
Typical Memory Arrangement
|
- Text segment: This is the machine instructions that are executed by the CPU. Usually the segment is sharable so that only a single copy needs to be in memory for frequently executed programs. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.
- Initialized data segment: This is usually just called the data segment and it contains 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.
- Uninitialized data segment: This segment is 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.
- Stack: This is 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) is saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables. By utilizing a stack in this fashion, C functions can be recursive.
- Heap: Dynamic memory allocation usually takes place on the heap. Historically the heap has been located between the top of the uninitialized data and the bottom of the stack.
Subsections
Next: Examples&Exercises:
Up: OPERATING SYSTEMS LABORATORY VIII
Previous: Examples&Exercises:
Contents
Cem Ozdogan
2009-05-11