Overview
This project is a custom-built allocator written entirely in C. It mimics the behavior memory allocation in C. It does not yet support calloc or realloc. It can allocate any variable since it uses void pointers. The vmalloc function returns a pointer to the memory allocated.
Features
- Implemented a custom heap allocator in C with manual memory management
- Designed and integrated custom versions of
malloc
andfree
- Managed memory blocks with metadata headers for allocation tracking
- Handled splitting and coalescing of memory blocks to reduce fragmentation
- Included error checking and boundary handling for robustness
Demo
Here's a quick demo of heap allocator in action:

Sample Code
struct block_header* best_fit(struct block_header* header, size_t size){
struct block_header* current = header;
struct block_header* goal = NULL;
size_t current_size;
while(current->size_status != VM_ENDMARK){
current_size = BLKSZ(current);
int isallocated = current->size_status & VM_BUSY;
if(current_size == size && !isallocated){
return current;
} else if(current_size > size && (goal == NULL || BLKSZ(goal) > current_size) && !isallocated){
goal = current;
}
current = (struct block_header*)((char*)current + current_size);
}
return goal;
}
Explore the Code
Check out the full project on GitHub, or download it directly.
What I Learned
This project strengthened my understanding of how C allocate memory. I learned memory allocation works and how block splitting and merging works. . It strengthened my grasp of pointer arithmetic, data structures, and systems-level debugging.