lecture 20: memory manager data structures
we thought through what data structs would be used to implement the
memory manager.
"fred's simplest" was an ordered-by-address linked list that
contained:
refnum addr size next-ptr
we also talked about a linked that that had entries for both allocated
and free blocks. in combination, these blocks would fully populate
the addr space:
free? refnum addr size next-ptr
if free = 0, then it's an allocation.
if free = 1, then it's a hole.
brian suggested optimization of making refnum do double-duty: if
refnum != 0, then it's allocated; otherwise, it's free.
this method is good because it's easy to find holes: just search thru
free blocks.
OTOH, when you do an alloc, it's more work: you have to split a free
block into an alloc block and the remaining hole block (unless it's a
perfect fit, in which case you replace the free block with an alloc
block, but this would be rare).
Also, when you do dealloc, you have to look at neighbors and possibly
combine any previous and next free blocks into one bigger one.
so the "fred's simplest" method is simpler, because for dealloc, you
just unlink the block that stored the allocation data.
with this simpler method, in order to find free blocks, you have to
search thru the list.
also talked about buddy system, and mathematical algorithm (using log
base 2, 2^n, and ceiling) to figure out powers of two. (or use
precomputed array of power of 2 sizes, which is a reasonable simple
approach.)