Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations > Class Template Reference

#include <freelist.hpp>

Public Types

using allocator = Allocator
 

Public Member Functions

 freelist_base (size_t minSize, size_t maxSize) noexcept
 
 ~freelist_base ()
 
void set_min_max (size_t minSize, size_t maxSize) noexcept
 
size_t min_size () const noexcept
 
size_t max_size () const noexcept
 
block allocate (size_t n) noexcept
 
bool reallocate (block &b, size_t n) noexcept
 
bool owns (const block &b) const noexcept
 
void deallocate (block &b) noexcept
 

Static Public Attributes

static constexpr unsigned pool_size = PoolSize
 
static constexpr unsigned number_of_batch_allocations = NumberOfBatchAllocations
 
static constexpr bool supports_truncated_deallocation = Allocator::supports_truncated_deallocation
 
static constexpr unsigned alignment = Allocator::alignment
 

Detailed Description

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
class alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >

The FreeListBase allocator is a generic implementation of a free list pool Users shall use the alb::freelist or the alb::shared_freelist. This class serves a pool of memory blocks and holds them in a list of free blocks Each block's MinSize and MaxSize define the area of blocks sizes that are handled with this allocator. It held until PoolSize blocks. More requested deallocations a forwarded to the Allocator for deallocation. NumberOfBatchAllocations specifies how blocks are allocated by the Allocator. MinSize and MaxSize can be set at runtime by instantiating this with ALB::DynasticDynamicSet. Except the moment of instantiation, this allocator is thread safe and all operations are lock free.

Template Parameters
SharedSet to true, for a multi threaded usage, otherwise to false
AllocatorThen allocator that should be used, when a new resource is needed

Definition at line 47 of file freelist.hpp.

Constructor & Destructor Documentation

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::freelist_base ( size_t  minSize,
size_t  maxSize 
)
inlinenoexcept

Constructs a FreeListBase with the specified bounding edges This c'tor is just available if the template parameter MinSize and MaxSize are set to DynasticDynamicSet. (Otherwise the compiler will tell ;-)

Parameters
minSizeThe lower boundary accepted by this Allocator
maxSizeThe upper boundary accepted by this Allocator

Definition at line 80 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::~freelist_base ( )
inline

Frees all resources. Beware of using allocated blocks given by this allocator after calling this.

Definition at line 89 of file freelist.hpp.

Member Function Documentation

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
block alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::allocate ( size_t  n)
inlinenoexcept

Provides a block. If it is available in the pool, then this will be reused. If the pool is empty, then a new block will be created and returned. The passed size n must be within the boundary of the allocator, otherwise an empty block will returned. Depending on the parameter NumberOfBatchAllocations not only one new block is allocated, but as many as specified.

Parameters
nThe number of requested bytes. The result is aligned to the upper boundary.
Returns
The allocated block

Definition at line 141 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
void alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::deallocate ( block b)
inlinenoexcept

Appends the block to the free list if it is not filled up. The given block is reset

Parameters
bThe block to free

Definition at line 222 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
size_t alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::max_size ( ) const
inlinenoexcept

Returns the upper boundary

Definition at line 126 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
size_t alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::min_size ( ) const
inlinenoexcept

Returns the lower boundary

Definition at line 119 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
bool alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::owns ( const block b) const
inlinenoexcept

Checks the ownership of the given block

Parameters
bThe block to check
Returns
True, it is owned by this allocator

Definition at line 213 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
bool alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::reallocate ( block b,
size_t  n 
)
inlinenoexcept

Reallocates the given block. In this case only trivial case can lead to a positive result. In general reallocation to a different size > 0 is not supported by this allocator.

Parameters
bThe block to reallocate
nThe new size
Returns
True, if the reallocation was successful.

Definition at line 201 of file freelist.hpp.

template<bool Shared, class Allocator, size_t MinSize, size_t MaxSize, unsigned PoolSize, unsigned NumberOfBatchAllocations>
void alb::v_100::freelist_base< Shared, Allocator, MinSize, MaxSize, PoolSize, NumberOfBatchAllocations >::set_min_max ( size_t  minSize,
size_t  maxSize 
)
inlinenoexcept

Set the min and max boundary of this allocator. This method is just available if the template parameter MinSize and MaxSize are set to DynasticDynamicSet. (Otherwise the compiler will tell ;-)

Parameters
minSizeThe lower boundary accepted by this Allocator
maxSizeThe upper boundary accepted by this Allocator

Definition at line 105 of file freelist.hpp.


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