A tiny, educational memory allocator that manages a fixed-size heap using a singly linked free list. It demonstrates block splitting, freeing, and coalescing with a debug heap dump.
- Fixed-size 1 MiB heap stored in a static array
- Simple free-list allocator with block splitting
- Coalescing of adjacent free blocks on free
- Debug helper to print heap layout
Requirements:
- CMake 4.2 or newer
- A C compiler that supports C11
Build steps:
cmake -S . -B build
cmake --build build./build/memory_allocatorThe program runs a small allocation/free sequence and prints heap dumps after each step.
voidheap_init(void);
void*xmalloc(size_tsize);
voidxfree(void*ptr);
voidheap_dump(void);- CMakeLists.txt - CMake build configuration
- main.c - allocator implementation and demo