Re:Show HN: I wrote a minimal memory allocator in C
by masterphai on Tuesday November 25, 2025 @08:44PM
(#46053210)
Nice writeup - it’s always refreshing to see a minimal allocator with a clean explanation rather than a full-blown production-grade system.
One thing worth calling out (building on what canyp mentioned) is that once you start caring about allocator performance, the conceptual model shifts away from “RAM as a byte array” toward “cache lines + page boundaries + TLB behavior”. A surprising amount of allocator behavior is dictated by how predictable your access patterns are to the L1/L2 caches rather than the actual heap layout.
In a previous toy allocator I built, the biggest wins came from aligning allocations to cache-line multiples and keeping metadata in a separate, tightly packed region. It reduced false sharing and made fragmentation surprisingly easier to reason about.
Curious whether you plan to explore thread safety next via per-thread arenas or a lock-free free-list - both approaches are fun rabbit holes.
One thing worth calling out (building on what canyp mentioned) is that once you start caring about allocator performance, the conceptual model shifts away from “RAM as a byte array” toward “cache lines + page boundaries + TLB behavior”. A surprising amount of allocator behavior is dictated by how predictable your access patterns are to the L1/L2 caches rather than the actual heap layout.
In a previous toy allocator I built, the biggest wins came from aligning allocations to cache-line multiples and keeping metadata in a separate, tightly packed region. It reduced false sharing and made fragmentation surprisingly easier to reason about.
Curious whether you plan to explore thread safety next via per-thread arenas or a lock-free free-list - both approaches are fun rabbit holes.