nngn
Loading...
Searching...
No Matches
nngn::tagging_allocator< D, A > Class Template Reference

Generic implementation of a malloc(3)-style allocator with headers. More...

#include <tagging.h>

Inheritance diagram for nngn::tagging_allocator< D, A >:
Collaboration diagram for nngn::tagging_allocator< D, A >:

Classes

struct  rebind
 

Public Types

using block_type = typename D::block_type
 
using value_type = typename D::value_type
 
using pointer = value_type*
 
using allocator
 

Public Member Functions

 tagging_allocator (void)=default
 
 tagging_allocator (const tagging_allocator &rhs)
 
tagging_allocatoroperator= (const tagging_allocator &rhs)
 
template<tagging_descriptor D1, typename A1 >
 tagging_allocator (const tagging_allocator< D1, A1 > &rhs)
 
 tagging_allocator (const allocator &a)
 
 tagging_allocator (tagging_allocator &&) noexcept=default
 
tagging_allocatoroperator= (tagging_allocator &&) noexcept=default
 
 ~tagging_allocator (void)=default
 
pointer allocate (std::size_t n) noexcept
 Allocates n objects (n.b.: only one header is added).
 
template<typename I >
requires (detail::has_typed_alloc<allocator, I>)
pointer allocate (std::size_t n, I i) noexcept
 Typed allocation (see nngn::tracking_allocator).
 
pointer reallocate (pointer p, std::size_t n) noexcept
 
void deallocate (pointer p, std::size_t n) noexcept
 
const allocatorget_allocator (void) const
 
template<typename I >
auto allocate (std::size_t n, I i) noexcept -> pointer requires(detail::has_typed_alloc< allocator, I >)
 

Static Private Member Functions

static pointer to_ptr (char *p)
 
static char * raw_from_ptr (pointer p)
 
static auto alloc_size (std::size_t n)
 

Private Attributes

allocator alloc = {}
 

Detailed Description

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
class nngn::tagging_allocator< D, A >

Generic implementation of a malloc(3)-style allocator with headers.

Objects are allocated using T::block_type (e.g. nngn::alloc_block), meaning a header is added to each allocation. This tagging is transparent: after template instantiation, the interface deals only with T::block_type::value_type objects.

The following are conditionally supported based on whether they are supported in the upstream allocator A:

See also
nngn::tagging_descriptor
nngn::alloc_block

Member Typedef Documentation

◆ allocator

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
using nngn::tagging_allocator< D, A >::allocator
Initial value:
typename std::allocator_traits<A>::template rebind_alloc<char>

◆ block_type

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
using nngn::tagging_allocator< D, A >::block_type = typename D::block_type

◆ pointer

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
using nngn::tagging_allocator< D, A >::pointer = value_type*

◆ value_type

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
using nngn::tagging_allocator< D, A >::value_type = typename D::value_type

Constructor & Destructor Documentation

◆ tagging_allocator() [1/5]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
nngn::tagging_allocator< D, A >::tagging_allocator ( void )
default

◆ tagging_allocator() [2/5]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
nngn::tagging_allocator< D, A >::tagging_allocator ( const tagging_allocator< D, A > & rhs)
inline

◆ tagging_allocator() [3/5]

template<tagging_descriptor D, typename A >
template<tagging_descriptor D1, typename A1 >
nngn::tagging_allocator< D, A >::tagging_allocator ( const tagging_allocator< D1, A1 > & rhs)

◆ tagging_allocator() [4/5]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
nngn::tagging_allocator< D, A >::tagging_allocator ( const allocator & a)
inlineexplicit

◆ tagging_allocator() [5/5]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
nngn::tagging_allocator< D, A >::tagging_allocator ( tagging_allocator< D, A > && )
defaultnoexcept

◆ ~tagging_allocator()

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
nngn::tagging_allocator< D, A >::~tagging_allocator ( void )
default

Member Function Documentation

◆ alloc_size()

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
static auto nngn::tagging_allocator< D, A >::alloc_size ( std::size_t n)
inlinestaticprivate

◆ allocate() [1/3]

template<tagging_descriptor D, typename A >
auto nngn::tagging_allocator< D, A >::allocate ( std::size_t n)
noexcept

Allocates n objects (n.b.: only one header is added).

Here is the call graph for this function:

◆ allocate() [2/3]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
template<typename I >
requires (detail::has_typed_alloc<allocator, I>)
pointer nngn::tagging_allocator< D, A >::allocate ( std::size_t n,
I i )
noexcept

Typed allocation (see nngn::tracking_allocator).

◆ allocate() [3/3]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
template<typename I >
auto nngn::tagging_allocator< D, A >::allocate ( std::size_t n,
I i ) -> pointer requires(detail::has_typed_alloc<allocator, I>)
noexcept
Here is the call graph for this function:

◆ deallocate()

template<tagging_descriptor D, typename A >
void nngn::tagging_allocator< D, A >::deallocate ( pointer p,
std::size_t n )
noexcept

◆ get_allocator()

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
const allocator & nngn::tagging_allocator< D, A >::get_allocator ( void ) const
inline

◆ operator=() [1/2]

template<tagging_descriptor D, typename A >
auto nngn::tagging_allocator< D, A >::operator= ( const tagging_allocator< D, A > & rhs)

◆ operator=() [2/2]

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
tagging_allocator & nngn::tagging_allocator< D, A >::operator= ( tagging_allocator< D, A > && )
defaultnoexcept

◆ raw_from_ptr()

template<tagging_descriptor D, typename A >
char * nngn::tagging_allocator< D, A >::raw_from_ptr ( pointer p)
staticprivate
Here is the call graph for this function:

◆ reallocate()

template<tagging_descriptor D, typename A >
requires (detail::has_realloc<A>)
auto nngn::tagging_allocator< D, A >::reallocate ( pointer p,
std::size_t n )
noexcept

◆ to_ptr()

template<tagging_descriptor D, typename A >
auto nngn::tagging_allocator< D, A >::to_ptr ( char * p)
staticprivate
Here is the caller graph for this function:

Member Data Documentation

◆ alloc

template<tagging_descriptor D, typename A = std::allocator<typename D::block_type::value_type>>
allocator nngn::tagging_allocator< D, A >::alloc = {}
private

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