This repository implements a basic block-based heap allocator in C to illustrate core ideas in dynamic memory management.
The allocator manages a fixed-size heap using a doubly linked list of metadata blocks and provides heap_alloc and heap_free.
- Fixed-size heap (
HEAP_SIZE) - Fixed-size blocks (
BLOCK_SIZE) - Metadata stored separately from heap payload
- First-fit contiguous block allocation
- Allocation tracking via allocation IDs
- Heap memory obtained using
mmap
A single mmap region is logically divided into:
- Metadata region: an array of
block_metadatastructures - Heap region: the memory returned to the caller
Each metadata entry corresponds to exactly one fixed-size heap block.