127 static constexpr
size_t kBlockAlignment =
alignof(std::max_align_t);
134 size_t blocks_per_chunk{0};
149 bool prealloc{
false};
150 size_t batch_size{16U};
162 size_t blocks_per_chunk{0};
163 size_t block_size{0};
164 uint64_t hit_count{0};
165 uint64_t deallocate_count{0};
166 uint64_t in_use_blocks{0};
167 uint64_t chunk_count{0};
168 uint64_t upstream_alloc_count{0};
169 uint64_t upstream_alloc_bytes{0};
180 uint64_t alloc_count{0};
181 uint64_t alloc_bytes{0};
182 uint64_t dealloc_count{0};
244 [[nodiscard]]
void*
allocate(
size_t bytes,
size_t alignment = kBlockAlignment) noexcept;
253 void deallocate(
void* p,
size_t bytes,
size_t alignment = kBlockAlignment) noexcept;
271 [[nodiscard]] std::vector<
TierStats> get_stats() const noexcept;
291 void reset_stats() noexcept;
303 void clear() noexcept;
311 void trim() noexcept;
330 [[nodiscard]] static
Config get_default_config();
346 static
MemoryPool& global_instance(
bool use_env_level = true);
349 size_t find_tier(
size_t bytes) const noexcept;
352 std::unique_ptr<Impl> impl_;
Per-tier free-list pool with runtime statistics and oversized passthrough.
Definition: memory_pool.h:118
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 and cross-shard batch size.
Definition: memory_pool.h:147
std::vector< Tier > tiers
Tier descriptors; empty or all-sentinel selects bypass mode.
Definition: memory_pool.h:148
Statistics for allocations that bypass the tier free lists.
Definition: memory_pool.h:179
Per-tier runtime statistics snapshot.
Definition: memory_pool.h:160
Descriptor for one size class.
Definition: memory_pool.h:132