Professional Documents
Culture Documents
Classifying Information Stored in Memory Memory Management in A Uniprogrammed System
Classifying Information Stored in Memory Memory Management in A Uniprogrammed System
OS OS OS
● Program instructions (unchangeable) 2200 2200 2200
Classifying Information
Segments of a Process
Stored in Memory (cont.)
n Binding time (when is space allocated?): n Process’ memory is divided into logical
● Static: before program starts running
segments (text, data, bss, heap, stack)
n Program code, static global variables ● Some are read-only, others read-write
(initialized and uninitialized)
● Some are known at compile time, others
● Dynamic: as program runs grow dynamically as program runs
n Procedure stack, dynamic storage (space
allocated by malloc or new) n Who assigns memory to segments?
n The loader loads the completed program n Compiling, linking, and loading is
into memory where it can be executed sufficient for static memory
● Loads code and initialized data segments ● Code, constants, static variables
into memory at specified location
● Leaves space for uninitialized data (bss) n In other cases, static allocation is not
sufficient:
● Returns value of start address to
operating system ● Need dynamic storage — programmer
may not know how much memory will be
n Alternatives in loading (next 2 lectures…) needed when program runs
n Use malloc or new to get what’s
● Absolute loader — loads executable file at necessary when it’s necessary
fixed location n For complex data structures (e.g., trees),
allocate space for nodes on demand
● Relocatable loader — loads the program
at an arbitrary memory location specified ● OS doesn’t know in advance which
by OS (needed for multiprogramming, not procedures will be called (would be
for uniprogramming) wasteful to allocate space for every
n Assembler and linker assume program will variable in every procedure in advance)
start at location 0
● OS must be able to handle recursive
n When program is loaded, loader modifies
procedures
all addresses by adding the real start
location to those addresses
7 Fall 1998, Lecture 22 8 Fall 1998, Lecture 22
Running the Program — Running the Program —
Dynamic Memory Allocation Dynamic Memory Allocation (cont.)