xentara-utils v2.0.4
The Xentara Utility Library
|
A lock-free pool that manages a number of preallocator memory locations for objects. More...
#include <xentara/utils/lockFree/Pool.hpp>
Public Types | |
using | value_type = Element |
The element type. | |
using | allocator_type = Allocator |
The Allocator type. | |
using | size_type = typename std::allocator_traits< Allocator >::size_type |
The type used for sizes. | |
using | difference_type = typename std::allocator_traits< Allocator >::difference_type |
The type used for distances. | |
using | reference = value_type & |
A reference to an element. | |
using | const_reference = const value_type & |
A const reference to an element. | |
using | pointer = typename std::allocator_traits< Allocator >::pointer |
A pointer to an element. | |
using | const_pointer = typename std::allocator_traits< Allocator >::const_pointer |
A const pointer to an element. | |
Public Member Functions | |
constexpr | Pool () noexcept(noexcept(Allocator()))=default |
Constructs an empty pool with a default-constructed allocator. | |
constexpr | Pool (const Allocator &allocator) noexcept |
Constructs an empty pool with a specific allocator. | |
Pool (size_type capacity) | |
Constructor for a pool that can hold a specific number of elements. | |
Pool (size_type capacity, const Allocator &allocator) | |
Constructor for a pool that can hold a specific number of elements. | |
auto | allocate () -> pointer |
Allocates storage for an element. | |
auto | allocate (std::nothrow_t) noexcept -> pointer |
Allocates storage for an element if there is space left. | |
auto | allocateWithIndex () -> std::pair< pointer, size_type > |
Allocates storage for an element and returns a unique index for it. | |
auto | allocateWithIndex (std::nothrow_t) noexcept -> std::pair< pointer, size_type > |
Allocates storage for an element if there is space left, and returns a unique index for it. | |
auto | deallocate (pointer element) noexcept -> void |
Deallocates the storage of an element back to the pool. | |
auto | deallocateAt (size_type index) noexcept -> void |
Deallocates the storage of an element back to the pool using its index. | |
auto | deallocateAll () noexcept -> void |
Deallocates all allocated elements. | |
auto | reset (size_type size) -> void |
Reset the pool memory to a certain capacity. | |
auto | index (const_reference element) const noexcept -> size_type |
Get a unique index for an element that can be used to reference it. | |
auto | operator[] (size_type index) noexcept -> reference |
Get the element associated with an index. | |
auto | operator[] (size_type index) const noexcept -> const_reference |
Get the element associated with an index. | |
constexpr auto | capacity () const noexcept -> size_type |
Gets the maximum number of elements the pool can hold. | |
constexpr auto | max_size () const noexcept -> size_type |
Gets the maximum possible capacity. | |
A lock-free pool that manages a number of preallocator memory locations for objects.
Element | the element type for which memory is allocated |
Allocator | the allocator for the element type |
using xentara::utils::lockFree::Pool< Element, Allocator >::allocator_type = Allocator |
The Allocator type.
using xentara::utils::lockFree::Pool< Element, Allocator >::const_pointer = typename std::allocator_traits<Allocator>::const_pointer |
A const pointer to an element.
using xentara::utils::lockFree::Pool< Element, Allocator >::const_reference = const value_type & |
A const reference to an element.
using xentara::utils::lockFree::Pool< Element, Allocator >::difference_type = typename std::allocator_traits<Allocator>::difference_type |
The type used for distances.
using xentara::utils::lockFree::Pool< Element, Allocator >::pointer = typename std::allocator_traits<Allocator>::pointer |
A pointer to an element.
using xentara::utils::lockFree::Pool< Element, Allocator >::reference = value_type & |
A reference to an element.
using xentara::utils::lockFree::Pool< Element, Allocator >::size_type = typename std::allocator_traits<Allocator>::size_type |
The type used for sizes.
using xentara::utils::lockFree::Pool< Element, Allocator >::value_type = Element |
The element type.
|
constexprdefaultnoexcept |
Constructs an empty pool with a default-constructed allocator.
A pool created with this constructor has a capacity of 0 and cannot hold any elements. You must make room for the elements using reset() before allocation storage for any elements.
|
explicitconstexprnoexcept |
Constructs an empty pool with a specific allocator.
A pool created with this constructor has a capacity of 0 and cannot hold any elements. You must make room for the elements using reset() before allocation storage for any elements.
allocator | The allocator |
|
explicit |
Constructor for a pool that can hold a specific number of elements.
Creates a pool of the given size and fills it with default-inserted values.
capacity | The number of entries to create room for |
|
explicit |
Constructor for a pool that can hold a specific number of elements.
Creates a pool of the given size and fills it with default-inserted values.
capacity | The number of entries to create room for |
allocator | The allocator |
auto xentara::utils::lockFree::Pool< Element, Allocator >::allocate | ( | ) | -> pointer |
Allocates storage for an element.
std::length_error | The pool is exhausted |
Rethrows | any exception thrown by the element constructor. |
|
noexcept |
Allocates storage for an element if there is space left.
This function will return a nullptr rather than throwing an exception if the pool is exhausted.
auto xentara::utils::lockFree::Pool< Element, Allocator >::allocateWithIndex | ( | ) | -> std::pair<pointer, size_type> |
Allocates storage for an element and returns a unique index for it.
std::length_error | The pool is exhausted |
|
noexcept |
Allocates storage for an element if there is space left, and returns a unique index for it.
This function will return a nullptr rather than throwing an exception if the pool is exhausted.
|
constexprnoexcept |
Gets the maximum number of elements the pool can hold.
|
noexcept |
Deallocates the storage of an element back to the pool.
element | An element previously returned by allocate() or allocateWithIndex(). If you pass nullptr, the function does nothing. |
|
noexcept |
Deallocates all allocated elements.
|
noexcept |
Deallocates the storage of an element back to the pool using its index.
index | The index of an element previously returned by allocate() or allocateWithIndex() |
|
noexcept |
Get a unique index for an element that can be used to reference it.
element | An element allocated using allocate() |
|
constexprnoexcept |
Gets the maximum possible capacity.
|
noexcept |
Get the element associated with an index.
index | An element index previously retuned by index() for an element that still exists. |
|
noexcept |
Get the element associated with an index.
index | An element index previously retuned by index() for an element that still exists. |
auto xentara::utils::lockFree::Pool< Element, Allocator >::reset | ( | size_type | size | ) | -> void |
Reset the pool memory to a certain capacity.
size | The new capacity of the pool |