Fixed-size aligned pool allocator for high-performance simulations. More...
#include <cstddef>
#include <cstdlib>
#include <new>
#include <mutex>
#include <cassert>
Go to the source code of this file.
Classes | |
struct | PoolAllocator |
Fast aligned bump allocator for multithreaded simulations. More... | |
Fixed-size aligned pool allocator for high-performance simulations.
This header defines PoolAllocator
, a fast linear allocator (aka bump allocator) for use in performance-critical systems such as simulation engines, numerical benchmarks, and cache-sensitive applications.
Rather than relying on general-purpose allocators (new
, malloc
, std::allocator
), which incur heap metadata overhead, internal fragmentation, and non-deterministic latency, this allocator uses a fixed-size, prealigned buffer and allocates memory by incrementing a single offset.
There is no deallocation — memory is reclaimed in bulk using reset()
.
malloc
, tcmalloc
, or jemalloc.thread_local
, there is no need for synchronization.Each call to allocate<T>()
performs:
The backing buffer is allocated once via std::aligned_alloc(64, size)
at construction. All alignment is handled manually at runtime — there is no dependency on STL allocators.
allocate<T>(align)
to override alignment (e.g., for 32-byte loads)_mm256_load_pd
(AVX2)_mm512_load_pd
(AVX-512)vld1q_f64
(NEON)Allocator.TempJob
and custom C++ enginesAllocator | Alloc Speed | Dealloc Speed | Fragmentation | Thread Safety | Notes |
---|---|---|---|---|---|
malloc/free | Medium | Medium | High | ✖ (unless locked) | General-purpose heap |
PoolAllocator | O(1) | reset() | None | ✅ (via thread_local) | Requires manual control |
STL allocator | Varies | Safe | Medium | Thread-safe (some) | Safer, but slower |
reset()
to reusenullptr
on overflow; user must size correctlystd::aligned_alloc()
Designed and tuned by Leon for use in SIMD-intensive Monte Carlo benchmarking, this allocator emphasizes low-latency allocation, predictable memory behavior, and tight coupling to modern cache and instruction pipelines.
Definition in file pool.hpp.