Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Practice build · Operating systems and the machine

Build your own Memory Allocator

Your own malloc, free, calloc and realloc on top of sbrk or mmap, loaded into real programs with LD_PRELOAD.

  • Intermediate
  • About 6–12 h
  • 4 checkpoints
  • 3 tutorials · C

Pick a tutorial, then check yourself at each checkpoint. Work in any language you like.

Choose a tutorial

Why build it

Heap bugs such as use-after-free, double free and fragmentation make sense once you have managed block headers and free lists yourself.

You will be able to

  • Explain how the heap grows with sbrk or mmap and what a block header stores.
  • Implement a free list with block splitting and coalescing.
  • Reason about alignment, fragmentation and the cost of an allocation strategy.
  • Debug memory errors with Valgrind or AddressSanitizer.

Skills it exercises

Recommended on Operating Systems & Linux.

Checkpoints

How you know you are there

Work in any language. Each checkpoint ends with something you can run or observe, so you can check it yourself.

  1. Checkpoint 1Self-check

    Bump allocator

    Done when: malloc returns 16-byte-aligned memory from sbrk, and a test allocates 10,000 blocks of random size and writes every byte without crashing.

  2. Checkpoint 2Self-check

    Free and reuse

    Done when: Freed blocks go on a free list and are reused first-fit; in an allocate/free loop the heap stops growing.

  3. Checkpoint 3Self-check

    Split and coalesce

    Done when: Large free blocks are split, neighbours merge on free, and a fragmentation test reports heap size before and after.

  4. Checkpoint 4Self-check

    Real programs

    Done when: With calloc and realloc added, LD_PRELOAD=./libmymalloc.so ls -la and a Python one-liner run correctly on your allocator.

Stretch goals

  • Size-class bins for small allocations.
  • Thread safety with a lock, then per-thread arenas.
  • mmap for large allocations.
Follow a tutorial

Step-by-step guides

Pick one in a language you know (tutorial languages: C). They open on the author’s site.

Practice builds are self-paced: Tech Atlas does not track them or count them as evidence. To show a skill, take its knowledge check from the skill page.

Tutorials come from codecrafters-io/build-your-own-x (CC0, snapshot of 2026-07-14, commit aa17439; links checked on 2026-10-19). Each tutorial belongs to its author and keeps its own licence; Tech Atlas links to it and does not host it. Briefs, checkpoints and the mapping to skills are Tech Atlas editorial drafts.