tp::OverallocationBehavior struct

Specifies the overallocation behavior of a pool. This can be useful for reducing the frequency of allocations at the cost of potentially higher memory usage.

Public static functions

static auto Exact() -> OverallocationBehavior
Creates a behavior of no overallocation that allocates exactly the requested amount.

Constructors, destructors, conversion operators

OverallocationBehavior(float requestFactor, float growFactor, uint64_t minAllocationSize)
Creates the specified overallocation behavior.

Public functions

auto apply(uint64_t requestedSize, uint64_t poolSize) const -> uint64_t
Applies the overallocation behavior to the requested size, returning the desired allocation size.

Function documentation

tp::OverallocationBehavior::OverallocationBehavior(float requestFactor, float growFactor, uint64_t minAllocationSize)

Creates the specified overallocation behavior.

Parameters
requestFactor The factor applied to requested allocation sizes. Must be greater or equal to 1.
growFactor The factor applied to the total size of all allocations. Must be greater or equal to 1.
minAllocationSize The size of the smallest allocation allowed to be made. The units are dependent on the specific pool.

Given a new allocation request, the size of the actual allocation to be made is calculated with the following formula: max(floor(requestedSize * requestFactor), floor(poolSize * (growFactor - 1.0)), minAllocationSize) where requestedSize is the size of the requested allocation and poolSize is the sum of all allocations made by the pool.

uint64_t tp::OverallocationBehavior::apply(uint64_t requestedSize, uint64_t poolSize) const

Applies the overallocation behavior to the requested size, returning the desired allocation size.

Parameters
requestedSize The requested size of the allocation.
poolSize The size of all allocations made by the pool so far.