Custom C Memory Allocator
Tru Bui
A lightweight malloc/free implementation written in C supporting block splitting,
coalescing, boundary tags, segregated free lists, and LD_PRELOAD interposition.
Designed to replace glibc's allocator at runtime for real-world testing.
Your browser does not support the video tag.
Key Features
Segregated free lists
Boundary tags with left/right block tracking
Coalescing and block splitting
Thread-safe allocator (global mutex)
OS chunk growth using sbrk()
Implements malloc, free, calloc, realloc
Override glibc using LD_PRELOAD
Usage
$ gcc -shared -fPIC -o libmymalloc.so myMalloc_sharedlib.c -ldl -pthread
$ LD_PRELOAD=./libmymalloc.so /bin/echo hello
$ LD_PRELOAD=./libmymalloc.so ls -l
Technologies & Concepts
Heap management and memory layout
Segregated free lists
Boundary tag coalescing
Pointer arithmetic & metadata layout
Dynamic linking & LD_PRELOAD
Thread safety & mutex locking
Low-level system calls (sbrk(), write())
Contact me for source code