Technology1 min read

The lost malloc()

By · Published by Everything Blog

In short

The recovered Unix V4 source code illustrates several early techniques used to handle dynamic system memory before standardized patterns emerged. Within the C compiler toolset, a basic routine called `alloc` relied on `sbrk()` to linearly assign memory without ever freeing it during program execution. Meanwhile, precursor functions authored by Dennis Ritchie required developers to manage explicit maps and supply specific object sizes to deallocate resources. This design allowed the operating system to actively partition system assets across designated areas like `coremap` and `swapmap`.

Key points

  • The fourth edition of Unix established core POSIX architectural concepts while rewriting…: The fourth edition of Unix established core POSIX architectural concepts while rewriting the majority of its kernel in C.
  • Early compiler routines omitted memory freeing entirely because allocated resources were…: Early compiler routines omitted memory freeing entirely because allocated resources were meant to persist for the program's full runtime.
  • Primitive precursors to `mfree()` required explicit object sizes to properly partition re…: Primitive precursors to `mfree()` required explicit object sizes to properly partition resources across designated memory regions.

Sources checked by our analysis pipeline: 1

(Sorry, I couldn't resist not putting a catchy title :)

Prompted by another project idea that popped into my mind, I did some Unix archaeology and looked at the original sources. This is the most fun I've ever had reading someone else's code - probably due to the historical significance. But also because of how delightfully approachable it was, compared to modern monstrocities.

This is a short(-ish) post regarding how they handled the mundane and boring task of allocating and managing memory (in C). In the future I'd like to read more about Unix the OS, its design, architecture & implementation.

A long time ago...

In a PDP far, far away, our journey begins with the fourth edition of Unix, released November '73, more than half a century ago. C actually first appeared in the second edition, released the year before, but wasn't extensively used. V4 is special because even the majority of the kernel was written in (let's call it "medieval") C by that point. The system had grown, however, and it was quite capable. You'll find that many…

Technology