vt::pool::Pool struct

A core VT component that manages efficient pools of memory for quick allocation/deallocation.

Highly efficient memory pool that is not thread-safe. Utilizes fixed-size buckets with free-list to quickly allocate and de-allocate.

Base classes

template<typename T>
struct vt::runtime::component::Component<Pool>
Component class for a generic VT runtime module, CRTP'ed over the component's actual type

Public types

enum class ePoolSize { Small = 1, Medium = 2, Large = 3, Malloc = 4 }
Different pool sizes: small, medium, large, and the backup malloc.
using SizeType = size_t
using HeaderType = Header
using HeaderManagerType = HeaderManager
template<int64_t num_bytes_t>
using MemoryPoolType = MemoryPoolEqual<num_bytes_t>
template<int64_t num_bytes_t>
using MemoryPoolPtrType = std::unique_ptr<MemoryPoolType<num_bytes_t>>

Constructors, destructors, conversion operators

Pool()
System construction of the pool component.

Public functions

auto name() -> std::string override
Get the name of the component.
auto alloc(size_t const& num_bytes, size_t oversize = 0) -> std::byte*
Allocate some number of bytes plus extra size at the end.
void dealloc(std::byte*const buf)
De-allocate a pool-allocated buffer.
auto getPoolType(size_t const& num_bytes, size_t const& oversize) const -> ePoolSize
Decided which pool bucket to target based on size.
auto remainingSize(std::byte*const buf) const -> SizeType
Get remaining bytes for a pool allocation.
auto allocatedSize(std::byte*const buf) const -> SizeType
Get total allocated bytes for a pool allocation.
auto tryGrowAllocation(std::byte*const buf, size_t grow_amount) -> bool
Attempt to increase the size of an allocation without reallocating.
auto active() const -> bool
Whether the pool is enabled at compile-time.
auto active_env() const -> bool
Whether the pool is enabled at compile-time and used as the default allocator for messages.
template<typename SerializerT>
void serialize(SerializerT& s)

Enum documentation

enum class vt::pool::Pool::ePoolSize

Different pool sizes: small, medium, large, and the backup malloc.

Enumerators
Small

Small bucket

Medium

Medium bucket

Large

Large bucket

Malloc

Backup malloc allocation

Function documentation

std::byte* vt::pool::Pool::alloc(size_t const& num_bytes, size_t oversize = 0)

Allocate some number of bytes plus extra size at the end.

Parameters
num_bytes in main payload
oversize in extra bytes
Returns pointer to new allocation

void vt::pool::Pool::dealloc(std::byte*const buf)

De-allocate a pool-allocated buffer.

Parameters
buf in the buffer to deallocate

ePoolSize vt::pool::Pool::getPoolType(size_t const& num_bytes, size_t const& oversize) const

Decided which pool bucket to target based on size.

Parameters
num_bytes in main payload
oversize in extra bytes
Returns enum ePoolSize of which pool to target

SizeType vt::pool::Pool::remainingSize(std::byte*const buf) const

Get remaining bytes for a pool allocation.

Parameters
buf in the buffer allocated from the pool
Returns number of extra bytes

\internalWhen using the memory pool, often extra bytes are at the end of the allocation because the user did not request the whole block assigned. Some components use this extra memory to pack in extra meta-data (or send serialized data) when sending a message.

SizeType vt::pool::Pool::allocatedSize(std::byte*const buf) const

Get total allocated bytes for a pool allocation.

Parameters
buf in the buffer allocated from the pool
Returns the total number of allocated bytes

\internalThe result of this includes both the requested and oversize bytes.

bool vt::pool::Pool::tryGrowAllocation(std::byte*const buf, size_t grow_amount)

Attempt to increase the size of an allocation without reallocating.

Parameters
buf in the buffer allocated from the pool that should be grown
grow_amount in the amount to grow the buffer
Returns false if the grow_amount is too large for the allocated block, true if the operation succeeded

\internalThe allocation will only be grown if grow_amount is less than or equal to the remaining size in the allocated block. If the grow_amount is too large, this function will return false and the allocation size will not be increased. On success, the new size will be reflected in the allocatedSize of the buffer.

bool vt::pool::Pool::active() const

Whether the pool is enabled at compile-time.

Returns whether its enabled

bool vt::pool::Pool::active_env() const

Whether the pool is enabled at compile-time and used as the default allocator for messages.

Returns whether its enabled