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

#include <allocator_with_stats.hpp>

Classes

struct  AllocationInfo
 
class  Allocations
 

Public Types

using statistic_type = typename traits::type_switch< std::atomic< size_t >, internal::no_atomic< size_t >, Shared >::type
 

Public Member Functions

block allocate (size_t n, const char *file=nullptr, const char *function=nullptr, int line=0) noexcept
 
void deallocate (block &b) noexcept
 
bool reallocate (block &b, size_t n) noexcept
 
template<typename U = Allocator>
std::enable_if
< traits::has_owns< U >::value,
bool >::type 
owns (const block &b) const noexcept
 
template<typename U = Allocator>
std::enable_if
< traits::has_expand< U >
::value, bool >::type 
expand (block &b, size_t delta) noexcept
 
Allocations allocations () const noexcept
 

Static Public Attributes

static const bool HasPerAllocationState
 
static MEMBER_ACCESSORS
constexpr bool 
supports_truncated_deallocation
 
static constexpr bool has_per_allocation_state = HasPerAllocationState
 
static constexpr unsigned alignment = Allocator::alignment
 

Detailed Description

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
class alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >

This Allocator serves as a facade in front of the specified allocator to collect statistics during runtime about all operations done on this instance. This is an implementation that is not intended to be used in a shared environment when statistics for file, line or time is enabled

In case that caller information shall be collected, the Allocator parameter is encapsulated with an ALB::affix_allocator. In this case alb::allocator_with_stats::AllocationInfo is in used as Prefix and so all caller information is prepended to every allocated block. Be aware that collecting of caller informations adds on top of each allocation sizeof(AllocatorWithStats::AllocationInfo) bytes! With a good optimizing compiler only the code for the enabled statistic information is created.

Template Parameters
AllocatorThe allocator that performs all allocations
FlagsSpecifies what kind of statistics get collected

Definition at line 209 of file allocator_with_stats.hpp.

Member Function Documentation

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
block alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::allocate ( size_t  n,
const char *  file = nullptr,
const char *  function = nullptr,
int  line = 0 
)
inlinenoexcept

The number of specified bytes gets allocated by the underlying Allocator. Depending on the specified Flag, the allocating statistic information is stored.

Parameters
nThe requested number of bytes
fileThe file name of the caller location (Only stored if CallerFile is enabled)
functionThe callers function (Only stored if CallerFunction is enabled)
lineThe callers line in source code (Only stored if CallerLine is enabled)

Definition at line 390 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
Allocations alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::allocations ( ) const
inlinenoexcept

Accessor to all currently outstanding memory allocations. The ownership of all elements belong to this class.

Returns
A container with all AllocationInfos

Definition at line 568 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
void alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::deallocate ( block b)
inlinenoexcept

The specified block gets freed by the underlaying Allocator Depending on the specified Flag, the deallocating statistic information is stored.

Parameters
bBlock to be freed

Definition at line 434 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
template<typename U = Allocator>
std::enable_if<traits::has_expand<U>::value, bool>::type alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::expand ( block b,
size_t  delta 
)
inlinenoexcept

The given block is passed to the underlying Allocator to be expanded This method is only available if the underlying allocator implements it. Depending on the specified Flag, the expand statistic information is stored.

Parameters
bThe block that should be expanded
deltaThe amount of bytes that should be tried to expanded
Returns
True, if the operation was successful

Definition at line 546 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
template<typename U = Allocator>
std::enable_if<traits::has_owns<U>::value, bool>::type alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::owns ( const block b) const
inlinenoexcept

The given block is passed to the underlying Allocator to be checked for ownership. This method is only available if the underlying Allocator implements it. Depending on the specified Flag, only the owns statistic information is stored.

Parameters
bThe block its ownership shall be checked

Definition at line 530 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
bool alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::reallocate ( block b,
size_t  n 
)
inlinenoexcept

The specified block gets reallocated by the underlaying Allocator Depending on the specified Flag, the reallocating statistic information is stored.

Parameters
bThe block that should be reallocated.
nThe new size. If zero, then a deallocation takes place
Returns
True, if the operation was successful

Definition at line 465 of file allocator_with_stats.hpp.

Member Data Documentation

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
const bool alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::HasPerAllocationState
static
Initial value:

Definition at line 320 of file allocator_with_stats.hpp.

template<bool Shared, class Allocator, unsigned Flags = alb::StatsOptions::All>
MEMBER_ACCESSORS constexpr bool alb::v_100::allocator_with_stats_base< Shared, Allocator, Flags >::supports_truncated_deallocation
static
Initial value:
=
Allocator::supports_truncated_deallocation

Definition at line 354 of file allocator_with_stats.hpp.


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