Memory Management Segments: F F F F F
Memory Management Segments: F F F F F
F For complex data structures (e.g., trees), allocate space F for tree traversal, expression evaluation, parsing, etc.
u Worst fit
F scan for the largest hole (hoping that the remaining hole will be
large enough to be useful)
5 6
u Which is better? Why??
Reclaiming memory Garbage collection
n When can memory be freed?
u Whenever programmer says to
u Garbage collection
F Used in LISP, Java
u Any way to do so automatically?
F Storage isn’t explicitly freed by a free operation; programmer
F Difficult if that item is shared (i.e., if there are multiple pointers
to it) just deletes the pointers and doesn’t worry about what it’s
pointing at
n Potential problems in reclamation
F When OS needs more storage space, it recursively searches
u Dangling pointers — have to make sure that everyone is finished
through all the active pointers and reclaims memory that no
using it one is using
u Memory leak — must not “lose” memory by forgetting to free it
F Makes life easier for application programmer, but is difficult to
when appropriate program the garbage collector
n Implementing automatic reclamation: F Often expensive — may use 20% of CPU time in systems that
u Reference counts use it
F Used by file systems • May spend as much as 50% of time allocating and
F OS keeps track of number of outstanding pointers to each automatically freeing memory
memory item
F When count goes to zero, free the memory
7 8
11 12
Static external relocation Static external relocation (cont.)
n Problems with static relocation:
u Safety — not satisfied — one process can access / corrupt
n Put the OS in the highest another’s memory, can even corrupt OS’s memory
address main main memory u Processes can not change size (why…?)
memory address memory
2400 2400 n Compiler and linker u Processes can not move after beginning to run (why would they
OS OS assume each process want to?)
2200 2200
1900 starts at address 0 u Used by MS-DOS, Windows, Mac OS
15 16
19 20
Memory
management
techniques
comparison