CadvancedcliAI generated

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

  1. 01

    Design the block header structure

    ~1.5h

    Define a header struct storing block size, free flag, and next-pointer, placed before each allocation.

  2. 02

    Implement my_malloc using a free list

    ~3h

    Search the free list for a suitable block, splitting it if larger than needed, or extend the heap with sbrk if none fits.

  3. 03

    Implement my_free with coalescing

    ~2.5h

    Mark blocks free and merge adjacent free blocks to reduce fragmentation.

  4. 04

    Implement my_calloc and my_realloc

    ~2h

    Build calloc on top of malloc with zeroing, and realloc that grows in place when possible or copies to a new block.

  5. 05

    Write a stress-test harness

    ~2h

    Write a test program that allocates/frees many random-sized blocks and validates no corruption or leaks occur.

  6. 06

    Benchmark against system malloc

    ~1.5h

    Compare allocation throughput of the custom allocator against libc malloc for various workloads.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~12.5h · 6 steps

Tech stack

unistd.h (sbrk)linked list allocator