Developer knowledge network · moderated exchange

UnreliableCode қауымдастығы

Әзірлеушілерді зерттеу, кері инженерия және кодтау қауымдастығы

Knowledge indexТірі
4Categories
919Threads
2.8KЖазбалар
Discussion

How to avoid memory fragmentation in high-performance C++ using custom Arena and Pool Allocators [StackOverflow Architecture Guide]

profiler_pat
Performance Hunter
MEMBER
Өкіл: 146
Қосылу күні: Aug 2019
Хабарламалар: 33
Рахмет: 31
3 апта бұрын · Jul 29, 2026 2:24 AM
#1

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).
memory_model_mook
Low-Level C Veteran
MEMBER
Өкіл: 163
Қосылу күні: Jan 2019
Хабарламалар: 11
Рахмет: 33
3 апта бұрын · Jul 29, 2026 8:30 AM
#2

Arena allocators are standard in web servers and game engines for per-frame or per-request scratch memory.

raii_clean_coder
Modern C++ Advocate
MEMBER
Өкіл: 190
Қосылу күні: Aug 2020
Хабарламалар: 20
Рахмет: 22
3 апта бұрын · Jul 29, 2026 9:43 PM
#3

Zero fragmentation, zero free-list traversal, and 100% cache locality.