Spaces is a single-file C allocator for Linux x86-64. It works as a drop-in malloc replacement, but its distinctive feature is that it also gives you explicit heap regions: create a heap for a subsystem, cap its memory, inspect every live allocation, share it across processes, and destroy the entire region in one call. Use cases: Parser/compiler arenas — free an entire million-node AST with one spaces_chunk_destroy() call instead of chasing pointers. Memory-bounded caches — set a hard ceiling on a chunk and let the allocator enforce it, so your server doesn't OOM at 3 AM. Runtime diagnostics — walk every live allocation in a heap region without an external profiler, recompilation, or debug build. gcc -O3 -pthread -fPIC -c spaces.c ar rc libspaces.a spaces.o gcc your_app.c -Wl,--whole-archive libspaces.a -Wl,--no-whole-archive -lpthread #include "spaces.h" // A bounded cache with enforced ceiling SpacesChunk cache = spaces_chunk_create(0); spaces_chunk_set_ceiling(cache, 256 * 1024 * 1024); void *p = spaces_chunk_alloc(cache, request_size, 0); if (!p) evict_oldest(); // ceiling enforced by the allocator spaces_chunk_destroy(cache); // instant teardown, everything freed // Or just use it as malloc — same binary, no code changes void *p = malloc(4096); free(p); I maintain a codebase where different subsystems need their own memory budgets, and where cleanup is the hardest part: a parser allocates a tree, the tree gets transformed, intermediate structures are discarded, and the final output lives in a separate region. With a standard allocator you either track and free every node, or you leak. I wanted an allocator where I could say: "this heap belongs to the parser; when parsing is done, destroy it." And I wanted the allocator itself to be fast enough that I wouldn't pay a tax for the organisational benefit. Existing options fell into two camps. The fast allocators (jemalloc, tcmalloc, mimalloc) are black boxes — fast malloc/free, nothing else. The region allocators (A...
First seen: 2026-03-28 12:39
Last seen: 2026-03-28 18:43