-
Notifications
You must be signed in to change notification settings - Fork 0
Blueprint 03 Memory
Dmdv edited this page Jul 11, 2026
·
1 revision
Source:
docs/blueprint/03-memory.mdin the main repository.
Rule: the fastest memory access is the one you never make.
Rule 2: never call the OS allocator on the critical path.
| Topic | Module |
|---|---|
| Arena / bump allocation | ll::Arena |
| std::pmr monotonic / unsync pool |
ll::PmrMonotonicArena, ll::PmrUnsyncPool
|
| Object pools | ll::ObjectPool<T,N> |
| Cache-line padding |
ll::kCacheLine, CacheLinePadded
|
| False sharing on queues | SPSC head/tail alignas
|
| mimalloc / jemalloc | Off critical path only (OPTIONAL/DOC) |
| AoS vs SoA | Guidance below |
#include "ll/arena.hpp"
#include "ll/pmr_arena.hpp"
ll::Arena arena(1 << 20); // pre-size at startup
// per message / window:
arena.reset();
auto* tmp = arena.create<MyState>(/*...*/);
// Or standard pmr:
ll::PmrMonotonicArena pmr(1 << 20);
auto* x = pmr.create<MyState>(/*...*/);
pmr.release();ll::ObjectPool<Order, 4096> orders; // pre-constructed
Order* o = orders.acquire();
// ...
orders.release(o);Two atomics on the same 64-byte line → bouncing cache lines between cores.
alignas(ll::kCacheLine) std::atomic<std::size_t> head;
alignas(ll::kCacheLine) std::atomic<std::size_t> tail;ll::SpscQueue does this by construction.
| Layout | Good when |
|---|---|
AoS (struct {px,qty}[]) |
Processing whole records together |
SoA (px[], qty[]) |
SIMD math over one field (VWAP qty*px streams) |
AoS cache line: [px0 qty0 px1 qty1 ...] — may waste bandwidth if only px needed
SoA cache line: [px0 px1 px2 px3 ...] — denser for SIMD
- Example:
examples/arena/main.cpp - Tests:
[ll][arena],[ll][pool],[ll][cache]
Wiki mirror of repository docs. Edit docs/ in the main repo, then python3 scripts/publish_wiki.py.