Why general-purpose malloc / new causes memory fragmentation in long-running services:
General allocators add metadata headers (8-16 bytes) to every allocation and search free lists, causing heap fragmentation over millions of allocations.
Arena (Bump) Allocator:
- Pre-allocates a contiguous 10MB memory block.
- Allocating is a simple pointer increment (
pCurrent += size). Sub-nanosecond execution time! - Freeing everything resets the pointer back to start in 1 CPU cycle (
pCurrent = pBase).