dynamic storage Flashcards
dynamic storage allocation
run-time allocation of storage for variables, structures, procedure calls
most lang, total amount storage cannot be determined at compile time (except fortran)
language features that require dynamic storage
- recursion
- pointers, explicit allocation
- dynamic data structs( list/dynamic arrays, trees, graphs)
- hof (lambda)
heap space via free-list
- available blocks of storage chained together in linkedlist
- when block is needed, removed from FL
- when block is reclaimed, insert into FL
disadvantage free list
- must search for block of right size
- fragmented memory
- expensive allocation, cheap reclamation
heap pointer method
- maintain available space as contiguous block of byes
- similar to stack pter, points to next available byte
- when object allocated, HP bumped by object size
disadvantages heap pointer
- requires compaction of live objects (pushing togeher)
- cheap allocation, expsensive reclamation
gc task
- find block of storage for dead objects
- make storage available for use
gc types
- mark/sweep: det set of all LIVe objects
2. ref count - during execution determine when object dies
mark/sweep live objects
- live means: pointer exists for x in activation record; register exists for x; object y in heap containing pointer to x and y is alive
- live objects found by graph traversal; start at root (local var on stack, global var, and registers)
- any object not reachable by root is dead
mark/sweep gc
- each obj has mark bit
- heap filled, program suspended, gc starts
- traversal (mark phase). sweep for those not marked.
mark/sweep disadvantage
- non compacting; use free list
- expensive allocation
- program suspension (stop and collect)
copying gc
- two heaps (FROM and TO)
- obj allocated in FROM. when from fills up, gc starts
- traversal copies FROM to TO live objects
- space FROM vs TO flipped
- use heap pointer (use forwarding address) in old object
fwding address vs ordinary pointer
fwding address is an address in TO space. no ordinary pter can point from FROM space into TO space
disadvantage cc gc
- stop and copy
- heap half size, can occur twice freq (but space can be swapped to disk)
ref counting
- ref count
- increment when copied
- decrement when object ref distroyed
- obj space reclaimed at rc = 0
- free list