A C++20 memory allocator focused on predictable latency for performance-critical, multi-threaded systems. It provides per-thread pools and fast fixed-size allocations, plus a linear arena for short-lived allocations. It integrates with the C++ standard allocator interface for drop-in use with STL containers.
- Thread-local pools to avoid cross-thread contention.
- Slab allocator with fixed-size classes for fast allocate/free.
- Linear (bump) allocator for bulk temporary allocations.
- STL-compatible
std::allocator-style interface. - Cache-line alignment options where appropriate.
- Each thread owns its pool; allocations never touch the global heap.
- Small allocations are routed to size-class slabs.
- Short-lived allocations can use a linear arena and be reset in O(1).
#include "memory_pool.hpp"
auto& pool = hft::get_thread_pool();
void* ptr = pool.allocate(256);
int* data = static_cast<int*>(ptr);
data[0] = 42;
pool.deallocate(ptr, 256);#include "stl_allocator.hpp"
std::vector<int, hft::FastPoolAllocator<int>> vec;
vec.push_back(1);#include "memory_pool.hpp"
hft::LinearAllocator arena(1024 * 1024);
void* p1 = arena.allocate(128);
void* p2 = arena.allocate(256);
arena.reset();make all
make test
make bench
make run
make cleanmkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)- C++20 compiler (GCC 10+, Clang 12+, MSVC 2019+)
- Recommended:
-O3 -march=native -flto
- Wilson et al., "The Memory Allocator Problem"
- TCMalloc (Thread-Caching Malloc)
- jemalloc: A Scalable Concurrent Malloc Implementation
MIT License. See LICENSE.
PRs welcome. Areas of interest:
- NUMA-aware allocation
- Huge page support
- Profiling hooks
- Additional size classes