Project 1: Memory Arena Allocator

A custom arena allocator from scratch that implements Odin’s allocator interface, with support for reset, free_all, and memory tracking.

Quick Reference

Attribute Value
Primary Language Odin
Alternative Languages C, Rust, Zig
Difficulty Level 2: Intermediate
Time Estimate Weekend
Knowledge Area Memory Management / Allocators
Tooling Custom implementation
Prerequisites Basic programming concepts, understanding of pointers

What You Will Build

A custom arena allocator from scratch that implements Odin’s allocator interface, with support for reset, free_all, and memory tracking.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Implementing the Allocator interface → maps to understanding Odin’s memory model
  • Managing a contiguous memory block → maps to low-level memory layout
  • Supporting alignment requirements → maps to CPU cache optimization
  • Integrating with the context system → maps to Odin’s implicit context

Key Concepts

Real-World Outcome

$ odin run arena_demo

Arena Allocator Demo
--------------------
Created arena with 1MB capacity

Allocating 1000 structs...
  Allocated: 1000 × Entity (48 bytes each)
  Total used: 48,000 bytes
  Alignment: 8-byte aligned ✓

Allocating strings...
  "Hello, Odin!" at 0x7f8b4c048000
  "Arena allocators are fast!" at 0x7f8b4c04800d

Reset arena (instant free)...
  Used: 0 bytes
  Capacity: 1,048,576 bytes

Stress test: 100,000 allocations...
  Arena time:  0.8ms
  Heap time:   45.2ms
  Speedup:     56x faster!

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_ODIN_PROGRAMMING_LANGUAGE.md
  • “Understanding the Odin Programming Language” by Karl Zylinski