pbr-cpp-memory-pool 1.2.0
Fixed-block-size O(1) memory pool — C++17 with an ANSI C public surface
Loading...
Searching...
No Matches
pool_memory_resource.hpp File Reference

std::pmr::memory_resource Adapter over Pool — ADR-0042. More...

Go to the source code of this file.

Macros

#define PBR_MEMORY_POOL_HAS_PMR   1
 

Detailed Description

std::pmr::memory_resource Adapter over Pool — ADR-0042.

PoolMemoryResource is the second Adapter the library ships (the sibling of the PoolAllocator<T> Adapter in ADR-0018). Where PoolAllocator<T> bridges the pool to the compile-time std::allocator_traits contract — one rebound allocator type per element type — PoolMemoryResource bridges the pool to the runtime std::pmr::memory_resource interface, so a single resource can back any number of heterogeneous std::pmr containers through std::pmr::polymorphic_allocator without the per-type rebind dance. This is exactly the "door left open" in ADR-0018's alternatives.

The adapter is a non-owning back-reference: it holds a Pool* and an upstream std::pmr::memory_resource*. The pool (and the upstream) must out-live this resource and every polymorphic_allocator / container bound to it — the same lifetime contract std::pmr::polymorphic_allocator places on its resource, and PoolAllocator<T> on its Pool.

Header-only; adds zero object code to the static library and zero per-pool metadata (ADR-0015 unaffected).

Availability. std::pmr is a C++17 facility, but some standard libraries shipped <memory_resource> late and freestanding profiles omit it. The whole adapter is therefore gated behind PBR_MEMORY_POOL_HAS_PMR, which is 1 only when <memory_resource> and its __cpp_lib_memory_resource feature-test macro are present. A consumer can test that macro before relying on the type; where it is 0 this header is a harmless no-op.

Definition in file pool_memory_resource.hpp.

Macro Definition Documentation

◆ PBR_MEMORY_POOL_HAS_PMR

#define PBR_MEMORY_POOL_HAS_PMR   1

Definition at line 52 of file pool_memory_resource.hpp.