pbr-cpp-memory-pool 1.1.2
Fixed-block-size O(1) memory pool — C++17 with an ANSI C public surface
Loading...
Searching...
No Matches
it::d4np::memorypool::InstrumentedPool Class Reference

Move-only Decorator over Pool that instruments allocation activity. More...

#include <instrumented_pool.hpp>

Public Member Functions

 InstrumentedPool (Pool &&pool) noexcept
 Adopt pool by move and start instrumenting it.
 
 InstrumentedPool (const InstrumentedPool &)=delete
 
InstrumentedPooloperator= (const InstrumentedPool &)=delete
 
 InstrumentedPool (InstrumentedPool &&other) noexcept
 Move-construct; the atomic counters are loaded and re-seeded (ADR-0025 §2).
 
InstrumentedPooloperator= (InstrumentedPool &&other) noexcept
 Move-assign; releases the current pool and re-seeds the counters + observers.
 
 ~InstrumentedPool ()
 Notify observers of destruction (ADR-0026); a moved-from instance has no observers.
 
void add_observer (PoolObserver &observer)
 Register an observer of lifecycle events (ADR-0026).
 
void * allocate ()
 Throwing allocation verb (ADR-0016 §2).
 
void * try_allocate () noexcept
 Non-throwing allocation verb (ADR-0016 §2).
 
void deallocate (void *block) noexcept
 Return a block; counts the deallocation for any non-null pointer.
 
PoolStats stats () const noexcept
 
void write_summary (std::ostream &os) const
 Write a one-line human-readable summary of the counters to os.
 
memory_pool_tnative_handle () noexcept
 
std::size_t block_size () const noexcept
 
std::size_t metadata_bytes () const noexcept
 

Static Public Member Functions

static std::optional< InstrumentedPoolmake (std::size_t block_size, std::size_t block_count)
 Factory mirroring Pool::makestd::nullopt on construction failure.
 
static std::optional< InstrumentedPoolmake_dynamic (std::size_t block_size, std::size_t block_count, std::size_t growth_factor)
 Factory mirroring Pool::make_dynamic (ADR-0024) — std::nullopt on failure.
 

Detailed Description

Move-only Decorator over Pool that instruments allocation activity.

Mirrors the Pool allocation surface (ADR-0016 verbs) and counts it. Copy is deleted (it owns a move-only Pool); move is hand-written because the atomic counters are not move-constructible.

Definition at line 98 of file instrumented_pool.hpp.

Constructor & Destructor Documentation

◆ InstrumentedPool() [1/2]

it::d4np::memorypool::InstrumentedPool::InstrumentedPool ( Pool &&  pool)
inlineexplicitnoexcept

Adopt pool by move and start instrumenting it.

Definition at line 101 of file instrumented_pool.hpp.

◆ InstrumentedPool() [2/2]

it::d4np::memorypool::InstrumentedPool::InstrumentedPool ( InstrumentedPool &&  other)
inlinenoexcept

Move-construct; the atomic counters are loaded and re-seeded (ADR-0025 §2).

The observer list is moved (leaving other empty, so its destructor notifies nobody).

Definition at line 128 of file instrumented_pool.hpp.

◆ ~InstrumentedPool()

it::d4np::memorypool::InstrumentedPool::~InstrumentedPool ( )
inline

Notify observers of destruction (ADR-0026); a moved-from instance has no observers.

Definition at line 156 of file instrumented_pool.hpp.

Member Function Documentation

◆ make()

static std::optional< InstrumentedPool > it::d4np::memorypool::InstrumentedPool::make ( std::size_t  block_size,
std::size_t  block_count 
)
inlinestatic

Factory mirroring Pool::makestd::nullopt on construction failure.

Definition at line 104 of file instrumented_pool.hpp.

◆ make_dynamic()

static std::optional< InstrumentedPool > it::d4np::memorypool::InstrumentedPool::make_dynamic ( std::size_t  block_size,
std::size_t  block_count,
std::size_t  growth_factor 
)
inlinestatic

Factory mirroring Pool::make_dynamic (ADR-0024) — std::nullopt on failure.

Definition at line 114 of file instrumented_pool.hpp.

◆ operator=()

InstrumentedPool & it::d4np::memorypool::InstrumentedPool::operator= ( InstrumentedPool &&  other)
inlinenoexcept

Move-assign; releases the current pool and re-seeds the counters + observers.

The pool being replaced is going away, so its observers get a destroyed event first — symmetric with the destructor (BUG-0003).

Definition at line 139 of file instrumented_pool.hpp.

◆ add_observer()

void it::d4np::memorypool::InstrumentedPool::add_observer ( PoolObserver observer)
inline

Register an observer of lifecycle events (ADR-0026).

Must out-live this pool.

Definition at line 161 of file instrumented_pool.hpp.

◆ allocate()

void * it::d4np::memorypool::InstrumentedPool::allocate ( )
inline

Throwing allocation verb (ADR-0016 §2).

Counts the success, or the failure on std::bad_alloc.

Definition at line 166 of file instrumented_pool.hpp.

◆ try_allocate()

void * it::d4np::memorypool::InstrumentedPool::try_allocate ( )
inlinenoexcept

Non-throwing allocation verb (ADR-0016 §2).

Counts success or in-band failure.

Definition at line 181 of file instrumented_pool.hpp.

◆ deallocate()

void it::d4np::memorypool::InstrumentedPool::deallocate ( void *  block)
inlinenoexcept

Return a block; counts the deallocation for any non-null pointer.

Definition at line 194 of file instrumented_pool.hpp.

◆ stats()

PoolStats it::d4np::memorypool::InstrumentedPool::stats ( ) const
inlinenoexcept
Returns
A snapshot of the current counters (ADR-0025 §2).

Definition at line 209 of file instrumented_pool.hpp.

◆ write_summary()

void it::d4np::memorypool::InstrumentedPool::write_summary ( std::ostream &  os) const
inline

Write a one-line human-readable summary of the counters to os.

Definition at line 216 of file instrumented_pool.hpp.

◆ native_handle()

memory_pool_t * it::d4np::memorypool::InstrumentedPool::native_handle ( )
inlinenoexcept
Returns
The underlying C handle (the decorator retains ownership).

Definition at line 224 of file instrumented_pool.hpp.

◆ block_size()

std::size_t it::d4np::memorypool::InstrumentedPool::block_size ( ) const
inlinenoexcept
Returns
The configured per-block size in bytes (ADR-0018 §3).

Definition at line 229 of file instrumented_pool.hpp.

◆ metadata_bytes()

std::size_t it::d4np::memorypool::InstrumentedPool::metadata_bytes ( ) const
inlinenoexcept
Returns
Per-pool metadata overhead in bytes (ADR-0015).

Definition at line 234 of file instrumented_pool.hpp.


The documentation for this class was generated from the following file: