|
VLink
2.0.0
A high-performance communication middleware
|
Size-class tiered memory pool with per-tier free lists and runtime statistics. 更多...
类 | |
| class | vlink::MemoryPool |
| Per-tier free-list pool with runtime statistics and oversized passthrough. 更多... | |
| struct | vlink::MemoryPool::Tier |
| Descriptor for one size class. 更多... | |
| struct | vlink::MemoryPool::Config |
| Constructor configuration grouping the tier list and the preallocation toggle. 更多... | |
| struct | vlink::MemoryPool::TierStats |
| Per-tier runtime statistics snapshot. 更多... | |
| struct | vlink::MemoryPool::OversizedStats |
| Statistics for allocations that bypass the tier free lists. 更多... | |
命名空间 | |
| vlink | |
Size-class tiered memory pool with per-tier free lists and runtime statistics.
MemoryPool dispatches each allocation request to one of a fixed pyramid of size classes. Every tier owns a singly-linked free list of fixed-size blocks plus a vector of upstream chunks; the chunk capacity starts small and doubles geometrically until it reaches the configured blocks_per_chunk. Requests larger than the biggest tier (or with an alignment stricter than alignof(std::max_align_t)) bypass the pool and route directly to ::operator new / ::operator delete.
| Source | When used |
|---|---|
Caller-supplied Config | MemoryPool(const Config&) with non-empty tiers |
get_default_config() (level 0..9) | global_instance(true) |
| Built-in level-3 balanced pyramid | Malformed input fallback or global_instance(false) |
Built-in level N row | MemoryPool(int level, bool prealloc) ctor |
* allocate(bytes, align) * | * v * +-----------------+ align > kBlockAlignment? +---------------------+ * | guard | ----------------------------------> | oversized bypass | * +-----------------+ | ::operator new | * | no +---------------------+ * v * +-----------------+ no fit ----> oversized bypass * | find_tier(bs) | * +--------+--------+ * | tier hit * v * +-----------------+ free list non-empty -> pop block * | per-tier lock | * +--------+--------+ * | free list empty * v * +-----------------+ ::operator new for next chunk * | upstream alloc | carve into N blocks of tier size * +-----------------+ *
| Method | What it releases | Concurrent traffic? |
|---|---|---|
clear / trim | Only fully-free chunks; live blocks preserved | Safe |
~MemoryPool | Every chunk unconditionally | Caller must quiesce |
noexcept and safe for concurrent use. Per-tier locking means traffic across different size classes does not contend. deallocate requires the same bytes value passed to allocate. allocate returns nullptr on upstream OOM and never throws.