A stack (bump) allocator reserves a fixed block of memory and tracks a single top-of-stack (tos) index so allocation is just returning the current pointer and adding the requested size to tos; freeing all allocations is a single tos reset. This gives extremely fast allocation and deallocation, at the cost of not running destructors automatically - placement new for construction and manual destructor calls are required for complex types. The pattern supports partial deallocation by saving and restoring tos for nested operations and is usable in multithreaded contexts by making tos updates atomic, though atomic contention can increase cache traffic; an alternative is one allocator per thread.
A double-headed stack allocator runs two independent tos indices at opposite ends of the same block so each side grows toward the other. That prevents fragmentation when two subsystems with different allocation/deallocation cadences (for example streamed level geometry versus per-character data) interleave allocations: each side can reset independently until the heads cross. A common variant stores variable-sized payloads on one side and an index/offset table on the other, enabling random access, removals, and compaction by updating offsets. The design is simple, efficient in memory-constrained systems, and straightforward to implement for parallel usage.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.