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

#include <bucketizer.hpp>

Public Types

using allocator = Allocator
 

Public Member Functions

block allocate (size_t n) noexcept
 
bool owns (const block &b) const noexcept
 
bool reallocate (block &b, size_t n) noexcept
 
void deallocate (block &b) noexcept
 
template<typename U = Allocator>
std::enable_if
< traits::has_deallocate_all
< U >::value, void >::type 
deallocate_all () noexcept
 

Static Public Member Functions

static constexpr size_t good_size (size_t n) noexcept
 

Public Attributes

Allocator _buckets [number_of_buckets]
 

Static Public Attributes

static constexpr bool supports_truncated_deallocation = false
 
static constexpr unsigned alignment = Allocator::alignment
 
static constexpr unsigned number_of_buckets = ((MaxSize - MinSize + 1) / StepSize)
 
static constexpr unsigned max_size = MaxSize
 
static constexpr unsigned min_size = MinSize
 
static constexpr unsigned step_size = StepSize
 

Detailed Description

template<class Allocator, unsigned MinSize, unsigned MaxSize, unsigned StepSize>
class alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >

The Bucketizer is intended to hold allocators with StepSize increasing buckets, within the range of [MinSize, MaxSize) E.g. MinSize = 17, MaxSize = 64, StepSize = 16 => BucketsSize[17, 32][33 48][48 64] It plays very well together with alb::freelist or alb::shared_freelist After instantiation any instance is as far thread safe as the Allocator is thread safe.

Template Parameters
AllocatorSpecifies which shall be handled in a bucketized way
MinSizeThe minimum size of the first bucket item
MaxSizeThe upper size of the last bucket item
StepSizeThe equidistant step size of the size of all buckets

Definition at line 36 of file bucketizer.hpp.

Member Function Documentation

template<class Allocator , unsigned MinSize, unsigned MaxSize, unsigned StepSize>
block alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >::allocate ( size_t  n)
inlinenoexcept

Allocates the requested number of bytes. The request is forwarded to the bucket with which edges are at [min,max] bytes.

Parameters
nThe number of bytes to be allocated
Returns
The Block describing the allocated memory

Definition at line 70 of file bucketizer.hpp.

template<class Allocator , unsigned MinSize, unsigned MaxSize, unsigned StepSize>
void alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >::deallocate ( block b)
inlinenoexcept

Frees the given block and resets it.

Parameters
bThe block, its memory should be freed

Definition at line 129 of file bucketizer.hpp.

template<class Allocator , unsigned MinSize, unsigned MaxSize, unsigned StepSize>
template<typename U = Allocator>
std::enable_if<traits::has_deallocate_all<U>::value, void>::type alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >::deallocate_all ( )
inlinenoexcept

Deallocates all resources. Beware of possible dangling pointers! This method is only available if Allocator::deallocate_all is available

Definition at line 149 of file bucketizer.hpp.

template<class Allocator , unsigned MinSize, unsigned MaxSize, unsigned StepSize>
bool alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >::owns ( const block b) const
inlinenoexcept

Checks, if the given block is owned by one of the bucket item

Parameters
bThe block to be checked
Returns
Returns true, if the block is owned by one of the bucket items

Definition at line 87 of file bucketizer.hpp.

template<class Allocator , unsigned MinSize, unsigned MaxSize, unsigned StepSize>
bool alb::v_100::bucketizer< Allocator, MinSize, MaxSize, StepSize >::reallocate ( block b,
size_t  n 
)
inlinenoexcept

Forwards the reallocation of the given block to the corresponding bucket item. If the length of the given block and the specified new size crosses the boundary of a bucket, then content memory of the block is moved to the new bucket item

Parameters
bThen Block its size should be changed
nThe new size of the block.
Returns
True, if the reallocation was successful.

Definition at line 102 of file bucketizer.hpp.


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