This struct is an implementation of C++ standard library type std::allocator
. It is to be used with container types provided by the C++ standard library in combination with ALib Allocators.
With the inclusion of module ALib Monomem in the ALib Distribution, this allocator is suitable to use cases of strict or weak monotonic allocation.
The following alias type definitions exist for this type, each addressing a specific allocator:
Along with this, shortcuts to the container types are likewise provided with:
While the dedicated container types provided with module ALib Containers offer a method named Reset (see for example HashTable::Reset), the C++ standard containers do not. This is a challenge because their internal memory will be invalid with a reset. For example, if allocator type MonoAllocator was used with calss std::vector
, there is no interface method that makes the vector "forget" its internal data array. Its method shrink_to_fit
by its specification is not forced to shrink anything or even dispose the data if the size was 0
when called. This is implementation-dependent.
The way out is as simple as radical: The container is just to be destructed and reconstructed "in place". This can be done using a C++ placement-new. The following code snippet demonstrates this:
std::unordered_set
and std::unordered_map
), is provided with sibling type StdContainerAllocatorRecycling.T | The type of objects to be allocated. |
TAllocator | The allocator type, as prototyped with Allocator. |
Definition at line 107 of file stdcontainerallocator.hpp.
#include <stdcontainerallocator.hpp>
Public Type Index: | |
using | allocBase = AllocatorMember<TAllocator> |
The allocator type that TAllocator specifies. | |
Public Type Index: inherited from StdContainerAllocatorBase< T, TAllocator > | |
using | AllocatorType = TAllocator |
The allocator type that TAllocator specifies. | |
using | const_reference = const T& |
Type definition as required by C++ library standards. | |
using | difference_type = ptrdiff_t |
Type definition as required by C++ library standards. | |
using | is_always_equal = std::false_type |
Type definition as required by C++ library standards. | |
using | reference = T& |
Type definition as required by C++ library standards. | |
using | size_type = size_t |
Type definition as required by C++ library standards. | |
using | value_type = T |
Type definition as required by C++ library standards. | |
Public Type Index: inherited from AllocatorMember< TAllocator > | |
using | AllocatorType = TAllocator |
Exposes the allocator type. | |
Public Method Index: | |
StdContainerAllocator ()=default | |
Parameterless constructor used with heap allocation. | |
constexpr | StdContainerAllocator (const StdContainerAllocator &) noexcept=default |
Defaulted copy constructor. | |
template<typename TSibling > | |
StdContainerAllocator (const StdContainerAllocator< TSibling, TAllocator > &origin) | |
template<typename TSibling , typename TEnableIf = ATMP_T_IF(void, ATMP_ISOF(TAllocator&, typename TSibling::allocator))> | |
StdContainerAllocator (const TSibling &origin) | |
constexpr | StdContainerAllocator (StdContainerAllocator &&) noexcept=default |
Defaulted move constructor. | |
StdContainerAllocator (TAllocator &pAllocator) | |
T * | allocate (size_t n, const void *=nullptr) |
void | deallocate (T *p, std::size_t n) |
template<typename U > | |
bool | operator!= (const StdContainerAllocator< U, TAllocator > &rhs) const noexcept |
template<typename U > | |
bool | operator== (const StdContainerAllocator< U, TAllocator > &rhs) const noexcept |
Public Method Index: inherited from StdContainerAllocatorBase< T, TAllocator > | |
size_t | max_size () const noexcept |
Public Method Index: inherited from AllocatorMember< TAllocator > | |
AllocatorMember ()=delete | |
Deleted default constructor. (The allocator has to be given with construction) | |
AllocatorMember (TAllocator &pAllocator) noexcept | |
AllocatorInterface< TAllocator > | AI () const noexcept |
TAllocator & | GetAllocator () const noexcept |
Additional Inherited Members | |
Protected Field Index: inherited from AllocatorMember< TAllocator > | |
TAllocator & | allocator |
A reference to the allocator. | |
using allocBase = AllocatorMember<TAllocator> |
The allocator type that TAllocator specifies.
Definition at line 111 of file stdcontainerallocator.hpp.
|
inline |
Copy constructor using an instance of different template type.
TSibling | The originating allocator's type (StdContainerAllocator<X>). |
origin | The originating allocator of type TSibling . |
Definition at line 124 of file stdcontainerallocator.hpp.
|
inline |
Copy constructor using an instance of different template type.
TSibling | The originating allocator's type (StdContainerAllocator<X>). |
origin | The originating allocator of type TSibling . |
Definition at line 132 of file stdcontainerallocator.hpp.
|
inline |
Constructor for the initial allocator instantiation.
pAllocator | The allocator. |
Definition at line 138 of file stdcontainerallocator.hpp.
|
inlinenodiscard |
Passes the allocation request to field allocator.
n | The number of requested objects to allocate storage for. |
Definition at line 180 of file stdcontainerallocator.hpp.
|
inline |
Frees the given array of objects.
p | Pointer to the previously allocated memory. |
n | The number of objects allocated. |
Definition at line 188 of file stdcontainerallocator.hpp.
|
inlinenoexcept |
Comparison operator.
U | The allocation type of the other allocator. |
rhs | The right hand side allocator. |
false
if this and rhs use the same allocator, true
otherwise. Definition at line 164 of file stdcontainerallocator.hpp.
|
inlinenoexcept |
Comparison operator.
U | The allocation type of the other allocator. |
rhs | The right hand side allocator. |
true
if this and rhs use the same allocator, false
otherwise. Definition at line 154 of file stdcontainerallocator.hpp.