Self-directed
Deterministic Memory Allocator

memory systems
concurrency
Project overview
Hybrid slab + TLSF allocator for HFT
A hybrid slab + TLSF memory allocator that serves every malloc/free in constant worst-case time and runs lock-free across threads.
Date
2026
Field
Quant
Stack
C++17, TLSF, Lock-free, mmap
O(1) worst case
0.24% fragmentation
lock-free (TSan-clean)
Context
A custom C++17 allocator built for the high-frequency-trading traffic profile, where a single multi-microsecond allocation stall during a market burst is a missed fill.




Deterministic Memory Allocator

The hard part
General-purpose allocators are tuned for the average case; low-latency systems instead need deterministic allocation with no tail stalls and no lock contention on the hot path.

What it took
- Built a slab engine with an intrusive free-list and zero per-object header for fixed-size records, routing header-less frees correctly through a sorted address-range registry.
- Implemented a Two-Level Segregated Fit engine whose two-level bitmap index finds a good-fit block in two hardware bit-scans (no loop), with splitting and boundary-tag coalescing that bounds internal waste below 1/32 ≈ 3.1%.
- Made the hot path lock-free across threads with per-thread caches over CAS-carved superblocks; cross-thread frees are pushed onto a lock-free MPSC remote-free stack threaded through the freed block's own memory and drained by the owner on its next allocation.


