what does a dynamic memory allocator do?
Three factors required for fragmentation to occur
Best-fit
Idea: tries to avoid breaking up large contiguous areas
-> Allocate the smallest free block that is large enough to fulfill the allocation request, during free coalesce adjacent blocks
- must search entire list
- Sawdust: external fragments of allocations are so small that over time leftovers with unusable sawdust are everywhere
Worst-fit
Idea: minimize sawdust by turning best-fit strategy around
-> Allocate the largest free block
- must search the entire list
- worse fragmentation that best-fit
First-fit
Idea: if you produce fragmentation anyway, try to optimize for allocation speed
-> Allocate the first hole that is big enough
-fastest allocation policy
-produces leftovers of variable size
Buddy Allocator
SLAB allocator
Why can’t you easily mitigate external fragmentation on the heap with compactification?
There is no memory translation on the heap, so compactification would break allocated areas- it would change start and other addresses referring to the allocated area and we can’t change pointers once they have been handed out
Which information can’t be extracted from the bitmap and needs to be kept separately?
A bitmap doesn’t store the length of an allocation: one can’t decide whether two adjacent allocations belong together or not from a bitmap alone.
A heap allocator need this info to release allocations.