ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::lang::StdRecyclingAllocator< T, TAllocator > Struct Template Reference

Description:

template<typename T, typename TAllocator>
struct alib::lang::StdRecyclingAllocator< T, TAllocator >

Implementation of std::allocator to be used with container types provided by the C++ standard library.

As the C+++ library's specification does not include details of the container class's implementation, this allocator uses type RTTRAllocator which detects node types automatically.

Attention
It cannot be guaranteed that a certain, uncommon implementation of the C++ library allocates memory in a way that this allocator truly recycles objects, and - even if the authors of ALib are optimistic hat this type works with any implementation - it is recommended to use the alternative container types found in this ALib Module.
See also
For background information about monotonic memory allocation, recycling, and the issues of C++ standard container types, see the Programmer's Manual of ALib Modules Containers" and \b Monomem. @tparam T The type of objects to be allocated. @tparam TAllocator The allocator type, as prototyped with class Allocator.

Definition at line 1197 of file allocation.hpp.

#include <allocation.hpp>

Public Type Index:

using AllocatorType = TAllocator
 Exposes template parameter TAllocator.
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 Field Index:

RTTRAllocator< TAllocator > & recycler
 The only member of this allocator type used to perform all duties.

Public Method Index:

constexpr StdRecyclingAllocator (const StdRecyclingAllocator &) noexcept=default
 Defaulted copy constructor.
constexpr StdRecyclingAllocator (RTTRAllocator< TAllocator > &pRecycler)
constexpr StdRecyclingAllocator (StdRecyclingAllocator &&) noexcept=default
 Defaulted move constructor.
template<typename TSibling>
 StdRecyclingAllocator (TSibling &StdRecyclingAllocator)
T * allocate (size_t n)
void deallocate (T *p, std::size_t n)
template<typename U>
bool operator!= (const StdRecyclingAllocator< U, TAllocator > &rhs) const noexcept
template<typename U>
bool operator== (const StdRecyclingAllocator< U, TAllocator > &rhs) const noexcept

Type Definition Details:

◆ AllocatorType

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::AllocatorType = TAllocator

Exposes template parameter TAllocator.

Definition at line 1207 of file allocation.hpp.

◆ const_reference

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::const_reference = const T&

Type definition as required by C++ library standards.

Definition at line 1206 of file allocation.hpp.

◆ difference_type

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::difference_type = ptrdiff_t

Type definition as required by C++ library standards.

Definition at line 1202 of file allocation.hpp.

◆ is_always_equal

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::is_always_equal = std::false_type

Type definition as required by C++ library standards.

Definition at line 1204 of file allocation.hpp.

◆ reference

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::reference = T&

Type definition as required by C++ library standards.

Definition at line 1205 of file allocation.hpp.

◆ size_type

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::size_type = size_t

Type definition as required by C++ library standards.

Definition at line 1201 of file allocation.hpp.

◆ value_type

template<typename T, typename TAllocator>
using alib::lang::StdRecyclingAllocator< T, TAllocator >::value_type = T

Type definition as required by C++ library standards.

Definition at line 1203 of file allocation.hpp.

Field Details:

◆ recycler

template<typename T, typename TAllocator>
RTTRAllocator<TAllocator>& alib::lang::StdRecyclingAllocator< T, TAllocator >::recycler

The only member of this allocator type used to perform all duties.

Definition at line 1213 of file allocation.hpp.

Constructor(s) / Destructor Details:

◆ StdRecyclingAllocator() [1/2]

template<typename T, typename TAllocator>
template<typename TSibling>
alib::lang::StdRecyclingAllocator< T, TAllocator >::StdRecyclingAllocator ( TSibling & StdRecyclingAllocator)
inline

Copy constructor using an instance of a different template type.

Template Parameters
TSiblingThe originating allocator's type (StdRecyclingAllocator<X>).
Parameters
StdRecyclingAllocatorThe originating allocator of type TSibling .

Definition at line 1228 of file allocation.hpp.

Here is the call graph for this function:

◆ StdRecyclingAllocator() [2/2]

template<typename T, typename TAllocator>
alib::lang::StdRecyclingAllocator< T, TAllocator >::StdRecyclingAllocator ( RTTRAllocator< TAllocator > & pRecycler)
inlineconstexpr

Constructor for the initial allocator instantiation.

Parameters
pRecyclerThe recycler to for allocations and deallocations.

Definition at line 1233 of file allocation.hpp.

Method Details:

◆ allocate()

template<typename T, typename TAllocator>
T * alib::lang::StdRecyclingAllocator< T, TAllocator >::allocate ( size_t n)
inlinenodiscard

Implementation of std::allocator interface. Dependent on whether a single or multiple object is requested, this method invokes either void * Get(size_t, size_t, const type_info&)  or void * AllocUnrelated(size_t, size_t, const type_info&)  on the field recycler.

Parameters
nThe number of requested objects to allocate storage for.
Returns
Pointer to the start of the array of n objects of type T.

Definition at line 1266 of file allocation.hpp.

◆ deallocate()

template<typename T, typename TAllocator>
void alib::lang::StdRecyclingAllocator< T, TAllocator >::deallocate ( T * p,
std::size_t n )
inline

Implementation of std::allocator interface. Dependent on whether a single or multiple objects are de-allocated (parameter n), this method invokes either void Recycle(void*, size_t, size_t, const type_info&)  or void RecycleChunk(void*, size_t, const type_info&)  on field recycler.

Parameters
pPointer to the object to deallocate.
nThe number of objects to de-allocate.

Definition at line 1282 of file allocation.hpp.

◆ operator!=()

template<typename T, typename TAllocator>
template<typename U>
bool alib::lang::StdRecyclingAllocator< T, TAllocator >::operator!= ( const StdRecyclingAllocator< U, TAllocator > & rhs) const
inlinenoexcept

Comparison operator.

Template Parameters
UThe allocation type of the other allocator.
Parameters
rhsThe right-hand side allocator.
Returns
false if this and rhs use the same recycler, true otherwise.

Definition at line 1252 of file allocation.hpp.

Here is the call graph for this function:

◆ operator==()

template<typename T, typename TAllocator>
template<typename U>
bool alib::lang::StdRecyclingAllocator< T, TAllocator >::operator== ( const StdRecyclingAllocator< U, TAllocator > & rhs) const
inlinenoexcept

Comparison operator.

Template Parameters
UThe allocation type of the other allocator.
Parameters
rhsThe right-hand side allocator.
Returns
true if this and rhs use the same recycler, false otherwise.

Definition at line 1244 of file allocation.hpp.

Here is the call graph for this function:

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