Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
alb::v_100::affix_allocator< Allocator, Prefix, Sufix > Class Template Reference

#include <affix_allocator.hpp>

Public Types

using allocator = Allocator
 
using prefix = Prefix
 
using sufix = Sufix
 

Public Member Functions

 affix_allocator (const affix_allocator &)=delete
 
affix_allocatoroperator= (const affix_allocator &)=delete
 
 affix_allocator (affix_allocator &&x)=default
 
affix_allocatoroperator= (affix_allocator &&x)=default
 
constexpr Prefix * outer_to_prefix (const block &b) const noexcept
 
constexpr Sufix * outer_to_sufix (const block &b) const noexcept
 
block allocate (size_t n) noexcept
 
void deallocate (block &b) noexcept
 
template<typename U = Allocator>
std::enable_if
< traits::has_owns< U >::value,
bool >::type 
owns (const block &b) const noexcept
 
bool reallocate (block &b, size_t n) noexcept
 
template<typename U = Allocator>
std::enable_if
< traits::has_expand< U >
::value, bool >::type 
expand (block &b, size_t delta) noexcept
 

Static Public Member Functions

static constexpr size_t good_size (size_t n)
 

Static Public Attributes

static constexpr bool supports_truncated_deallocation = Allocator::supports_truncated_deallocation
 
static constexpr unsigned alignment = Allocator::alignment
 
static constexpr size_t prefix_size
 
static constexpr size_t sufix_size
 

Detailed Description

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
class alb::v_100::affix_allocator< Allocator, Prefix, Sufix >

This allocator enables the possibility to surround allocated memory blocks with guards, ref-counter, mutex or etc. It is used by the alb::allocator_with_stats It automatically places an object of type Prefix before the returned memory location and an object of type Sufix after it. In case that they are of type affix_allocatorHelper::Empty nothing is inserted. Depending on the alignment of the used Allocator, Prefix, memory and Sufix are each aligned. Prefix and Sufix, if used, must be trivially copyable. (This cannot be statically asserted, because this would block the possibility to use this allocator as guard for memory under- or overflow. One should keep in mind, that using a Sufix is not CPU cache friendly!

Template Parameters
AllocatorThe allocator that is used as underlying allocator
PrefixIf defined, then an object of that kind is constructed in front of any returned block
SufixIf defined, then an object of that kind is constructed beyond any returned block

Definition at line 45 of file affix_allocator.hpp.

Member Function Documentation

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
block alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::allocate ( size_t  n)
inlinenoexcept

Allocates a Block of n bytes. Actually a Block of n + sizeof(Prefix) + sizeof(Sufix) bytes is allocated. Depending of the defines Prefix and Sufix types objects of this gets instantiated before and/or beyond the returned Block. If Zero bytes are allocated then no allocation at all takes places and an empty Block is returned.

Parameters
nSpecifies the number of requested bytes. n or more bytes are returned, depending on the alignment of the underlying Allocator.

Definition at line 128 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
void alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::deallocate ( block b)
inlinenoexcept

The given block gets deallocated. If Prefix or Sufix are defined then their d'tor(s) are called.

Parameters
bThe Block that should be freed.

Definition at line 154 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
template<typename U = Allocator>
std::enable_if<traits::has_expand<U>::value, bool>::type alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::expand ( block b,
size_t  delta 
)
inlinenoexcept

The method tries to expand the given block by at least delta bytes insito at the given location. This is only available if the underlaying Allocator implements ::expand().

Parameters
bThe block that should be expanded
deltaThe number of bytes that the given block should be increased
Returns
True, if the operation was successful.

Definition at line 220 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
constexpr Prefix* alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::outer_to_prefix ( const block b) const
inlinenoexcept

This Method returns on a given block the prefix.

Parameters
bThe block that was prefixed. The result is absolute unpredictable if a block is passed, that is not owned by this allocator!
Returns
Pointer to the Prefix before the given block

Definition at line 103 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
constexpr Sufix* alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::outer_to_sufix ( const block b) const
inlinenoexcept

This Method returns on a given block the sufix.

Parameters
bThe block that was sufixed. The result is absolute unpredictable if a block is passed, that is not owned by this allocator!
Returns
Pointer to the sufix before the given block

Definition at line 114 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
template<typename U = Allocator>
std::enable_if<traits::has_owns<U>::value, bool>::type alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::owns ( const block b) const
inlinenoexcept

If the underlying Allocator defines ::owns() this method is available. It returns true, if the given block is owned by this allocator.

Parameters
bThe Block that should be checked for ownership

Definition at line 177 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
bool alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::reallocate ( block b,
size_t  n 
)
inlinenoexcept

The given block gets reallocated to the new provided size n. Any potential defined Prefix and/or Sufix gets copied to the new location.

Parameters
bThe block that should be resized
nThe new size (n = zero means a deallocation)
Returns
True if the operation was successful

Definition at line 190 of file affix_allocator.hpp.

Member Data Documentation

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
constexpr size_t alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::prefix_size
static
Initial value:
=
std::is_same<Prefix, affix_helper::no_affix>::value ? 0 : internal::round_to_alignment(alignment, sizeof(Prefix))

Definition at line 80 of file affix_allocator.hpp.

template<class Allocator, typename Prefix, typename Sufix = affix_helper::no_affix>
constexpr size_t alb::v_100::affix_allocator< Allocator, Prefix, Sufix >::sufix_size
static
Initial value:
=
std::is_same<Sufix, affix_helper::no_affix>::value ? 0 : internal::round_to_alignment(alignment, sizeof(Sufix))

Definition at line 83 of file affix_allocator.hpp.


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