Algorithm for allocate (n)
size(block) = n + size(header)
Scan free list for
smallest block with nWords >= size(block)
If block not found
Failure (time for garbage collection!)
Else if free block nWords >= size(block) + threshold*
Split into a free block
and an in-use block
Free block nWords =
Free block nWords - size(block)
In-use block nWords = size(block)
Return pointer to in-use block
Else
Unlink block from free list
Return pointer to block
*Threshold must be at least size(header) + 1
to leave room for header and link
Threshold can be set higher to combat fragmentation
Allocation time is O(K)
(K = number of blocks in free list)