Contiguous Memory Allocator
Published:
Stack: C, operating systems, memory management
Overview
A educational contiguous memory allocator written in C. Instead of relying on malloc, it reserves one region of virtual memory with mmap and manages every byte of it by hand: allocating blocks, freeing them, coalescing neighbours, and compacting the region on demand.
This is a learning project focused on how allocators work under the hood: block headers, free lists, first/best/worst-fit placement, fragmentation, and compaction.
What I built
- A contiguous allocation model with explicit free and occupied regions.
- Fragmentation handling through memory compaction.
- Allocation strategies: first-fit, best-fit, and worst-fit.
What I learned
Compaction makes the fragmentation trade-off visible: reclaiming scattered free space requires moving live allocations, which is exactly the cost that non-contiguous memory models avoid. Comparing the placement strategies also shows how allocation policy affects fragmentation and throughput.
