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::PoolBuilder Class Reference

Fluent builder for configured Pool instances. More...

#include <memory_pool.hpp>

Public Member Functions

PoolBuilderwith_block_size (std::size_t block_size) noexcept
 Set the per-block size in bytes; must satisfy ADR-0009 §2 at build time.
 
PoolBuilderwith_block_count (std::size_t block_count) noexcept
 Set the block count; must satisfy ADR-0009 §3 at build time.
 
PoolBuilderwith_growth_factor (std::size_t growth_factor) noexcept
 Opt into dynamic growth with the given geometric factor (ADR-0024 §3).
 
std::optional< Poolbuild () const
 Produce a std::optional<Pool> from the accumulated configuration.
 

Detailed Description

Fluent builder for configured Pool instances.

Accumulates configuration through chainable with_* setters and produces a std::optional<Pool> on build(). The Builder pattern absorbs the future configuration-explosion (thread-safety strategy from Milestone 4, dynamic-growth policy from Milestone 5) without requiring ABI changes to the Pool ctor or to Pool::make. Adopted in ADR-0011 §2.

Usage:

if (auto pool = PoolBuilder{}
.build();
pool) {
void* block = pool->allocate();
// ...
}
Fluent builder for configured Pool instances.
PoolBuilder & with_block_size(std::size_t block_size) noexcept
Set the per-block size in bytes; must satisfy ADR-0009 §2 at build time.
PoolBuilder & with_block_count(std::size_t block_count) noexcept
Set the block count; must satisfy ADR-0009 §3 at build time.
std::optional< Pool > build() const
Produce a std::optional<Pool> from the accumulated configuration.

build() is const, so a configured builder can produce multiple identically-configured pools (useful for tests and for benchmark setup). A default-constructed builder has block_size_ == 0 and block_count_ == 0; calling build() on it returns std::nullopt — the deliberate fail-loud behaviour for forgotten configuration.

Definition at line 219 of file memory_pool.hpp.

Member Function Documentation

◆ with_growth_factor()

PoolBuilder & it::d4np::memorypool::PoolBuilder::with_growth_factor ( std::size_t  growth_factor)
noexcept

Opt into dynamic growth with the given geometric factor (ADR-0024 §3).

A factor >= 2 makes build() produce a dynamic pool via Pool::make_dynamic; the default (0) leaves the pool fixed-size. Under a lock-free build, a dynamic build returns std::nullopt (ADR-0024 §2).


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