next up previous contents
Next: Examples&Exercises: Up: OPERATING SYSTEMS LABORATORY VIII Previous: Examples&Exercises:   Contents

Memory Arrangement

Figure 2: Typical Memory Arrangement
\includegraphics[scale=0.7]{figures/proginmem.ps}
  1. 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.
  2. 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.
  3. 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 up previous contents
Next: Examples&Exercises: Up: OPERATING SYSTEMS LABORATORY VIII Previous: Examples&Exercises:   Contents
Cem Ozdogan 2009-05-11