Get the latest tech news

Untangling Lifetimes: The Arena Allocator


Making performant dynamic manual memory management in C feel almost like garbage collection.

The primary—and quite understandable—criticism people have of malloc and free, or what they call “manual memory management in C”, is that using it for granular allocations with varying lifetimes across several layers in a codebase can easily lead to a rat’s nest of complexity. The natural path for many C codebases is simply that of least (initial) resistance, which is to assume malloc and free as a suitable memory allocation interface (which is not necessarily unreasonable, given a lack of data), and so they will adopt it as a pattern. In other words, you may treat the operating system as “the ultimate garbage collector”— free ing memory when it is unnecessary will simply waste both your and the user’s time, and lead to code complexity and bugs that would otherwise not exist.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of lifetimes

lifetimes

Photo of Arena Allocator

Arena Allocator

Photo of Untangling Lifetimes

Untangling Lifetimes

Related news:

News photo

Visualize Ownership and Lifetimes in Rust

News photo

Safe and efficient C++ interoperability via non-escapable types and lifetimes