Custom Memory Allocator (malloc/free clone)
A from-scratch implementation of malloc, free, realloc, and calloc using sbrk() to manage a heap with a free-list allocator, including block splitting and coalescing. Learners practice low-level memory management, pointer arithmetic, and linked-list based allocator design in C.
- Estimate
- ~12.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
unistd.h (sbrk) · linked list allocator
Project roadmap
- 01
Design the block header structure
~1.5hDefine a header struct storing block size, free flag, and next-pointer, placed before each allocation.
- 02
Implement my_malloc using a free list
~3hSearch the free list for a suitable block, splitting it if larger than needed, or extend the heap with sbrk if none fits.
- 03
Implement my_free with coalescing
~2.5hMark blocks free and merge adjacent free blocks to reduce fragmentation.
- 04
Implement my_calloc and my_realloc
~2hBuild calloc on top of malloc with zeroing, and realloc that grows in place when possible or copies to a new block.
- 05
Write a stress-test harness
~2hWrite a test program that allocates/frees many random-sized blocks and validates no corruption or leaks occur.
- 06
Benchmark against system malloc
~1.5hCompare allocation throughput of the custom allocator against libc malloc for various workloads.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack