132 static constexpr
size_t kBlockAlignment =
alignof(std::max_align_t);
139 size_t blocks_per_chunk{0};
156 bool prealloc{
false};
157 size_t batch_size{16U};
158 bool lazy_scale{
false};
170 size_t blocks_per_chunk{0};
171 size_t block_size{0};
172 uint64_t hit_count{0};
173 uint64_t deallocate_count{0};
174 uint64_t in_use_blocks{0};
175 uint64_t chunk_count{0};
176 uint64_t upstream_alloc_count{0};
177 uint64_t upstream_alloc_bytes{0};
188 uint64_t alloc_count{0};
189 uint64_t alloc_bytes{0};
190 uint64_t dealloc_count{0};
252 [[nodiscard]]
void*
allocate(
size_t bytes,
size_t alignment = kBlockAlignment) noexcept;
261 void deallocate(
void* p,
size_t bytes,
size_t alignment = kBlockAlignment) noexcept;
279 [[nodiscard]] std::vector<
TierStats> get_stats() const noexcept;
299 void reset_stats() noexcept;
313 void clear() noexcept;
321 void trim() noexcept;
341 [[nodiscard]] static
Config get_default_config();
357 static
MemoryPool& global_instance(
bool use_env_level = true);
360 size_t find_tier(
size_t bytes) const noexcept;
363 std::unique_ptr<Impl> impl_;
Per-tier free-list pool with runtime statistics and oversized passthrough.
Definition: memory_pool.h:123
MemoryPool(const Config &config)
Constructs a tiered pool with an explicit configuration.
void * allocate(size_t bytes, size_t alignment=kBlockAlignment) noexcept
Allocates bytes of memory from the appropriate tier.
size_t get_tier_count() const noexcept
Returns the number of live managed tiers.
MemoryPool()
Constructs an empty pool in bypass mode.
void deallocate(void *p, size_t bytes, size_t alignment=kBlockAlignment) noexcept
Returns a block previously allocated through allocate to the pool.
~MemoryPool()
Releases every owned chunk unconditionally.
MemoryPool(int level, bool prealloc=false)
Constructs a tiered pool using the built-in pyramid for level.
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition: macros.h:174
Constructor configuration for tiers, preallocation, cross-shard batch size and lazy scaling.
Definition: memory_pool.h:154
std::vector< Tier > tiers
Tier descriptors; empty or all-sentinel selects bypass mode.
Definition: memory_pool.h:155
Statistics for allocations that bypass the tier free lists.
Definition: memory_pool.h:187
Per-tier runtime statistics snapshot.
Definition: memory_pool.h:168
Descriptor for one size class.
Definition: memory_pool.h:137