A user-space heap allocator implemented in C using mmap, supporting
malloc and free with a linked-list free list and first-fit
allocation strategy.
This project implements a simplified dynamic memory allocator to understand how heap management works internally.
Key features:
- Memory pool backed by
mmap - Linked-list free list
- First-fit allocation strategy
- Block splitting for efficient reuse
- Adjacent block coalescing to reduce fragmentation
- 8-byte memory alignment
- In-memory block metadata management
Each block stores metadata in-band:
typedef struct Block {
size_t size;
int is_free;
struct Block* next;
} Block;
Allocation flow:
- Align requested size to 8 bytes\
- Search free list (first-fit)\
- Split block if oversized\
- Return pointer past metadata
Free flow:
- Mark block as free\
- Coalesce with adjacent free block
gcc allocator.c -o allocator
./allocator
- Virtual memory management (
mmap) - Manual heap management
- Fragmentation control
- Pointer arithmetic
- Memory alignment
- Low-level systems programming
- Implement
realloc/calloc - Add boundary tags for bidirectional coalescing
- Add benchmarking vs glibc
malloc - Add thread safety