A low-level heap memory manager implemented in C/C++, exploring two distinct approaches to dynamic memory allocation from scratch — without relying on malloc or any standard allocator.
This project implements a custom heap allocator to deeply understand how memory management works at the OS boundary. Two allocator strategies are implemented, each with different trade-offs in complexity and control.
A fully functional heap allocator using the sbrk syscall to grow
the process data segment on demand.
How it works:
- Maintains a free list of memory blocks using a linked list structure
- Implements first-fit allocation strategy
- Coalesces adjacent free blocks to reduce fragmentation
- Uses
sbrk()to request additional memory from the OS when no suitable free block exists - Implements
malloc,free, andreallocequivalents
Key concepts demonstrated:
- Process memory layout (heap segment)
- Free list management and block metadata
- Internal and external fragmentation handling
- Memory alignment
An exploration of lower-level memory management using mmap to
allocate memory directly at the virtual memory page level.
Goal: Manage memory at page granularity, bypassing the traditional heap entirely and interacting directly with the OS virtual memory subsystem.
Concepts being explored:
mmap/munmapfor anonymous memory mapping- Page-aligned allocation
- Virtual memory layout and address space management
- Build specific structure for every type that is registered
Understanding how allocators work is foundational to systems programming and security research. Custom allocators will help me learn:
- How heap vulnerabilities like heap overflows, use-after-free, and double-free bugs arise at the implementation level
- The OS mechanisms (sbrk, mmap) that underpin all dynamic memory in user space
I plan in future to finish vm version and to add version small buckets, large bucker in order to understand memory better in terms of security and to add intrusive lists to all projects
- C / C++
- CMake
- Linux system calls (sbrk, mmap)
- Linked list block management