Custom Memory Allocator

Apr 17, 2025 ยท 1 min read
Custom Memory Allocator

Custom Memory Allocator in C

This project implements a custom memory allocator in C, mimicking the functionality of malloc, free, calloc, and realloc. It’s designed to simulate dynamic memory allocation using a fixed-size heap and linked list for memory block management โ€” no external libraries or OS-dependent memory functions used.

Features

  • Manual malloc, free, calloc, realloc implementation
  • First Fit and Best Fit allocation strategies (user selectable)
  • Block splitting and coalescing
  • Heap layout visualization with debug print
  • Memory usage statistics (used vs free)
  • Fully modular C code with header and source separation

๐Ÿ“ File Structure

.
โ”œโ”€โ”€ allocator.h      # Public interface for allocator functions
โ”œโ”€โ”€ allocator.c      # Core memory management logic
โ”œโ”€โ”€ main.c           # CLI interface and test runner
โ”œโ”€โ”€ README.md        # Project documentation

How to Compile & Run

gcc main.c allocator.c -o allocator
./allocator

Topics Covered

  • Low-level C programming
  • Memory and pointer management
  • Data structures (linked lists)
  • Embedded system fundamentals
  • Debugging and testing