nngn
Loading...
Searching...
No Matches
nngn::tracking_allocator< T, A > Class Template Reference

Allocator which tracks the amount of memory allocated. More...

#include <tracking.h>

Inheritance diagram for nngn::tracking_allocator< T, A >:
Collaboration diagram for nngn::tracking_allocator< T, A >:

Classes

struct  rebind
 

Public Types

using value_type = typename T::value_type
 
using pointer = typename T::pointer
 
using allocator
 

Public Member Functions

 tracking_allocator (void)=default
 
 tracking_allocator (T t)
 
 tracking_allocator (T t, const tracking_allocator &rhs)
 
 tracking_allocator (const tracking_allocator &rhs)
 
template<alloc_tracker T1, typename A1 >
 tracking_allocator (const tracking_allocator< T1, A1 > &rhs)
 
tracking_allocatoroperator= (const tracking_allocator &rhs)
 
 tracking_allocator (tracking_allocator &&) noexcept=default
 
tracking_allocatoroperator= (tracking_allocator &&) noexcept=default
 
 ~tracking_allocator (void)=default
 
const allocatorget_allocator (void) const
 
Ttracker (void)
 
const Ttracker (void) const
 
pointer allocate (std::size_t n) noexcept
 
void deallocate (pointer p, std::size_t n) noexcept
 
pointer reallocate (pointer p, std::size_t n) noexcept
 
template<typename I >
requires has_typed_alloc<I>
pointer allocate (std::size_t n, I i) noexcept
 
template<typename I >
requires has_typed_alloc<I>
auto allocate (std::size_t n, I ti) noexcept -> pointer
 

Private Attributes

T m_tracker = {}
 
allocator alloc = {}
 

Static Private Attributes

template<typename I >
static bool constexpr has_typed_alloc
 

Detailed Description

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
class nngn::tracking_allocator< T, A >

Allocator which tracks the amount of memory allocated.

This class exists mostly to conform to the allocator interface, the actual operations are delegated to the two template parameters, as described below.

The alloc_tracker type T should be the one which actually implements the tracking operations. An object of this type is stored internally — so it should be some kind of reference if the allocator is frequently copied — and one of its corresponding methods is called for each operation:

  • allocate(n): allocate(p, n), where p is the pointer just allocated.
  • deallocate(p, n): deallocate(p, n).

In addition, the following methods are called if the base allocator supports them:

  • allocate(n, t): allocate(p, n, t), as above but with the allocation type.
  • reallocate(p, n): reallocate(p, n).
Template Parameters
TType which contains tracking data and to which tracking operations are delegated.
ABase allocator to which all memory allocations are delegated.

Member Typedef Documentation

◆ allocator

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
using nngn::tracking_allocator< T, A >::allocator
Initial value:
typename std::allocator_traits<A>::template rebind_alloc<value_type>

◆ pointer

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
using nngn::tracking_allocator< T, A >::pointer = typename T::pointer

◆ value_type

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
using nngn::tracking_allocator< T, A >::value_type = typename T::value_type

Constructor & Destructor Documentation

◆ tracking_allocator() [1/6]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
nngn::tracking_allocator< T, A >::tracking_allocator ( void )
default

◆ tracking_allocator() [2/6]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
nngn::tracking_allocator< T, A >::tracking_allocator ( T t)
inlineexplicit

◆ tracking_allocator() [3/6]

template<alloc_tracker T, typename A >
nngn::tracking_allocator< T, A >::tracking_allocator ( T t,
const tracking_allocator< T, A > & rhs )

◆ tracking_allocator() [4/6]

template<alloc_tracker T, typename A >
nngn::tracking_allocator< T, A >::tracking_allocator ( const tracking_allocator< T, A > & rhs)

◆ tracking_allocator() [5/6]

template<alloc_tracker T, typename A >
template<alloc_tracker T1, typename A1 >
nngn::tracking_allocator< T, A >::tracking_allocator ( const tracking_allocator< T1, A1 > & rhs)

◆ tracking_allocator() [6/6]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
nngn::tracking_allocator< T, A >::tracking_allocator ( tracking_allocator< T, A > && )
defaultnoexcept

◆ ~tracking_allocator()

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
nngn::tracking_allocator< T, A >::~tracking_allocator ( void )
default

Member Function Documentation

◆ allocate() [1/3]

template<alloc_tracker T, typename A >
auto nngn::tracking_allocator< T, A >::allocate ( std::size_t n)
noexcept
Here is the caller graph for this function:

◆ allocate() [2/3]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
template<typename I >
requires has_typed_alloc<I>
pointer nngn::tracking_allocator< T, A >::allocate ( std::size_t n,
I i )
noexcept

◆ allocate() [3/3]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
template<typename I >
requires has_typed_alloc<I>
auto nngn::tracking_allocator< T, A >::allocate ( std::size_t n,
I ti ) -> pointer
noexcept

◆ deallocate()

template<alloc_tracker T, typename A >
void nngn::tracking_allocator< T, A >::deallocate ( pointer p,
std::size_t n )
noexcept

◆ get_allocator()

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
const allocator & nngn::tracking_allocator< T, A >::get_allocator ( void ) const
inline

◆ operator=() [1/2]

template<alloc_tracker T, typename A >
auto nngn::tracking_allocator< T, A >::operator= ( const tracking_allocator< T, A > & rhs)

◆ operator=() [2/2]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
tracking_allocator & nngn::tracking_allocator< T, A >::operator= ( tracking_allocator< T, A > && )
defaultnoexcept

◆ reallocate()

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
pointer nngn::tracking_allocator< T, A >::reallocate ( pointer p,
std::size_t n )
inlinenoexcept

◆ tracker() [1/2]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
T & nngn::tracking_allocator< T, A >::tracker ( void )
inline

◆ tracker() [2/2]

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
const T & nngn::tracking_allocator< T, A >::tracker ( void ) const
inline

Member Data Documentation

◆ alloc

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
allocator nngn::tracking_allocator< T, A >::alloc = {}
private

◆ has_typed_alloc

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
template<typename I >
bool constexpr nngn::tracking_allocator< T, A >::has_typed_alloc
staticconstexprprivate
Initial value:
=
requires(T t, pointer p, std::size_t n, I i) {
t.allocate(p, n, i);
}
Definition fundamental.h:41
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
#define T(f0, f1, f2)

◆ m_tracker

template<alloc_tracker T, typename A = std::allocator<typename T::value_type>>
T nngn::tracking_allocator< T, A >::m_tracker = {}
private

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