A high-performance, lock-free C++20 memory allocator designed for latency-sensitive applications.
- 🔒 Lock-Free Design - Uses atomic operations (CAS) instead of mutexes
- 🧵 Thread-Local Arenas - Zero-contention fast-path allocations via
thread_local - 📄 Hugepage Support - Reduces TLB misses and page fault jitter with 2MB pages
- ⚡ O(1) Allocation - Slab-based segregated free lists for constant-time operations
- 🎯 SIMD-Friendly - 16-byte minimum alignment for all allocations
- 📊 STL Compatible - Drop-in replacement for
std::allocator
#include <nexusalloc/nexusalloc.hpp>
#include <vector>
int main() {
// Optional: Lock memory to prevent page faults
nexusalloc::initialize();
// Use with STL containers
std::vector<int, nexusalloc::NexusAllocator<int>> vec;
vec.push_back(42);
// Or use directly
void* ptr = nexusalloc::allocate(64);
nexusalloc::deallocate(ptr, 64);
}# Debug build (default)
make build
# Release build
make build BUILD_TYPE=Release
# Run tests
make test
# Run benchmarks
make benchgraph TB
subgraph Application
APP[Your Code]
end
subgraph "NexusAllocator<T>"
ALLOC[STL Interface]
end
subgraph "Thread-Local Arena"
TLA[Per-Thread, Zero Contention]
S1["Slab<16>"]
S2["Slab<32>"]
S3["Slab<64>"]
SN["..."]
end
subgraph "Global Page Stack"
GPS[Lock-Free CAS]
end
subgraph "OS Layer"
HP["HugepageProvider<br/>(mmap + MAP_HUGETLB)"]
end
APP --> ALLOC
ALLOC --> TLA
TLA --> S1
TLA --> S2
TLA --> S3
TLA --> SN
S1 -.->|chunk request| GPS
S2 -.->|chunk request| GPS
S3 -.->|chunk request| GPS
SN -.->|chunk request| GPS
GPS -.->|page alloc| HP
| Range | Increment | Classes |
|---|---|---|
| 1-256 bytes | 16 bytes | 16, 32, 48, ..., 256 |
| 257-65536 bytes | Power of 2 | 512, 1024, ..., 65536 |
| >65536 bytes | Direct mmap | N/A |
# Check current hugepage allocation
cat /proc/meminfo | grep Huge
# Reserve hugepages (requires root)
echo 100 | sudo tee /proc/sys/vm/nr_hugepages