HeadlinesBriefing HeadlinesBriefing.com

Unix V4 Memory Allocation: Dennis Ritchie's malloc

Hacker News •
×

Exploring Unix V4 (November 1973) sources reveals fascinating early memory management. The C compiler's c20.c uses a simple linear allocator via `sbrk()`, aligning requests and extending the heap in 2000-byte chunks. On exhaustion it prints "Out of space" and exits — callers never check for NULL because the program lifetime is the allocation lifetime.

More intriguing is Dennis Ritchie's `malloc.c`, defining `malloc(mp, size)` and `mfree(mp, size, aa)` that operate on explicit map regions (`coremap`, `swapmap`) declared in `systm.h`. The caller supplies the region and, on free, the exact size. This arena-style interface avoids global heap fragmentation and makes bulk deallocation trivial — just discard the region.

These patterns — linear bump allocation for short-lived compilers, region-based allocators for the kernel — feel remarkably modern. They predate `malloc`/`free` as we know them and show how Unix's designers solved memory management with clarity and constraints that still instruct today.

Source: Hacker News · Summarized by HeadlinesBriefing