|
pbr-cpp-memory-pool 1.1.2
Fixed-block-size O(1) memory pool — C++17 with an ANSI C public surface
|
STL-compatible allocator vending storage from a Pool.
More...
#include <pool_allocator.hpp>
Public Types | |
| using | value_type = T |
| using | propagate_on_container_copy_assignment = std::false_type |
| using | propagate_on_container_move_assignment = std::false_type |
| using | propagate_on_container_swap = std::false_type |
| using | is_always_equal = std::false_type |
Public Member Functions | |
| PoolAllocator (Pool &pool) noexcept | |
Bind the adapter to pool. | |
| template<typename U > | |
| PoolAllocator (const PoolAllocator< U > &other) noexcept | |
Rebinding converting constructor — required by the Cpp17Allocator requirements so a container can build an allocator for its internal node type from the user-supplied PoolAllocator<T>. | |
| T * | allocate (std::size_t n) |
Allocate storage for n objects of T (ADR-0018 §2). | |
| void | deallocate (T *ptr, std::size_t n) noexcept |
| Return storage obtained from allocate. | |
| template<typename U > | |
| bool | operator== (const PoolAllocator< U > &rhs) const noexcept |
| Two adapters are equal iff they reference the same pool. | |
| template<typename U > | |
| bool | operator!= (const PoolAllocator< U > &rhs) const noexcept |
| Negation of operator==. | |
STL-compatible allocator vending storage from a Pool.
Routing (ADR-0018 §2). A request routes to the pool iff it is a single block that fits — n == 1, sizeof(T) <= pool.block_size(), and T is not over-aligned. Such requests are served by Pool::allocate (O(1), throwing std::bad_alloc on exhaustion per ADR-0016 §2). Every other request — n > 1, an over-aligned T, or a rebound node larger than the block — is delegated to over-aligned ::operator new / ::operator delete.
Because the standard guarantees deallocate(p, n) is called with the same n (and on the same allocator type, hence the same sizeof(T) / alignof(T)) as the matching allocate(n), and block_size() is invariant for the pool's lifetime, the routing predicate evaluates identically at allocate and deallocate time. Every pointer is therefore freed by exactly the path that allocated it, with no per-pointer bookkeeping.
As a result a single container may, over its lifetime, hold storage from both sources (e.g. a std::vector whose n == 1 initial capacity came from the pool and whose grown buffer came from the heap) — correct, if occasionally surprising.
Propagation (ADR-0018 §4). All three propagate_on_container_* traits are false_type; the adapter is stateful (is_always_equal is false_type) and two instances compare equal iff they reference the same Pool.
| T | Element type the allocator vends. Rebinding to any U (e.g. a container's internal node type) is the single-template-parameter default supplied by std::allocator_traits. |
Definition at line 70 of file pool_allocator.hpp.
| using it::d4np::memorypool::PoolAllocator< T >::value_type = T |
Definition at line 72 of file pool_allocator.hpp.
| using it::d4np::memorypool::PoolAllocator< T >::propagate_on_container_copy_assignment = std::false_type |
Definition at line 77 of file pool_allocator.hpp.
| using it::d4np::memorypool::PoolAllocator< T >::propagate_on_container_move_assignment = std::false_type |
Definition at line 78 of file pool_allocator.hpp.
| using it::d4np::memorypool::PoolAllocator< T >::propagate_on_container_swap = std::false_type |
Definition at line 79 of file pool_allocator.hpp.
| using it::d4np::memorypool::PoolAllocator< T >::is_always_equal = std::false_type |
Definition at line 81 of file pool_allocator.hpp.
|
inlineexplicitnoexcept |
Bind the adapter to pool.
The pool is not owned and must out-live this adapter, every copy of it, and every container that uses it (ADR-0018 §1).
Definition at line 88 of file pool_allocator.hpp.
|
inlinenoexcept |
Rebinding converting constructor — required by the Cpp17Allocator requirements so a container can build an allocator for its internal node type from the user-supplied PoolAllocator<T>.
Deliberately implicit (the rebind machinery relies on the implicit conversion); it is a trivial back-reference copy.
Definition at line 98 of file pool_allocator.hpp.
|
inline |
Allocate storage for n objects of T (ADR-0018 §2).
n contiguous T. | std::bad_alloc | on pool exhaustion (pool-eligible requests), on size_t overflow of n * sizeof(T), or from the fallback ::operator new. |
Definition at line 108 of file pool_allocator.hpp.
|
inlinenoexcept |
Return storage obtained from allocate.
n must be the value passed to the matching allocate call (a Cpp17Allocator guarantee), which keeps the pool/fallback routing deterministic.
Definition at line 124 of file pool_allocator.hpp.
|
inlinenoexcept |
Two adapters are equal iff they reference the same pool.
Definition at line 134 of file pool_allocator.hpp.
|
inlinenoexcept |
Negation of operator==.
Definition at line 140 of file pool_allocator.hpp.
Definition at line 148 of file pool_allocator.hpp.