A single-file C allocator with explicit heaps and tuning knobs

C dev drops 'Spaces'—a nuke-your-heap button; commenters brawl over speed, deja vu, and Zig

TLDR: A new one-file C memory tool, “Spaces,” promises per-subsystem heaps you can cap, inspect, share, and wipe in one go. Commenters split between praising the “nuke it” cleanup, calling out prior art (dlmalloc mspaces), doubting ultra-fast claims, roasting code style, and yelling “rewrite it in Zig,” making this a must-watch allocator feud.

Meet “Spaces,” a one-file C memory manager that promises a big red “destroy this heap” button. In plain English: it lets developers put different parts of an app in separate memory buckets, cap each bucket, peek at what’s inside, share buckets across processes, and then obliterate the whole thing with one call. The author says it’s fast enough to replace your usual malloc (the default memory grabber) and even brags a single data read on free costs ~5 nanoseconds. Cue the comment-section sirens.

Strongest take? Prior art police showed up early. One user pointed to dlmalloc and its “mspaces,” basically saying: “This was a thing.” That kicked off a classic “new idea vs. done-before” tug-of-war. Meanwhile, a performance skeptic clapped back at the “5 ns when cold” claim, calling it wildly optimistic, and another noted the project’s tcmalloc comparison used an old, abandoned version. Translation: the benchmark drama is real.

Then came the style roast—someone asked if the quirky curly-brace code blocks were machine-generated. And out of nowhere, Zig fans swerved in: “Why fight C when Zig’s allocator system already does this?” Cue the “just rewrite it in Zig” memes—and the backlash from C diehards.

Still, others loved the “push one button to free an entire parser tree” vibe and joked about finally sleeping through those 3 AM out-of-memory incidents. Allocator wars have entered the chat, and they’re spicy: speed claims, originality debates, weird code, and a surprise Zig subplot—all wrapped around a “nuke your heap” promise.

Key Points

  • Spaces is a single-file C allocator for Linux x86-64 that can replace malloc and provides explicit heap regions.
  • It supports creating per-subsystem heaps with hard memory ceilings, live-allocation walking, cross-process sharing, and one-call region teardown.
  • Quick-start instructions show building with gcc and ar, and using the API for a bounded cache or as a transparent malloc replacement.
  • The design trade-off: each free() reads a 64 KB slab header cache line (estimated ~5 ns when cold) to derive size class, thread, and region without external metadata.
  • Spaces aims to bridge fast allocators (jemalloc/tcmalloc/mimalloc) and region allocators (Apache APR pools, Loki) by offering speed plus region-style features and 62 API functions.

Hottest takes

what does your solution do better or different than dlmalloc's mspaces? — HexDecOctBin
I don't see how that could possibly be true. — jeffbee
just rewrite it all in zig — lstodd
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.