ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PoolResource< M > Class Template Reference

pools of the size classes of 8 bytes up to \( M \), for one thread at a time More...

#include <ADS/memory/PoolAllocator.h>

Public member functions

 PoolResource (void)
 the empty resource
 PoolResource (const PoolResource &)=delete
 no copy, since its objects and allocators point to it
PoolResource & operator= (const PoolResource &)=delete
 no copy, since its objects and allocators point to it
 ~PoolResource ()=default
 frees the blocks; the objects still alive are not destroyed
template<std::size_t b, std::size_t a = alignof( std::max_align_t )>
void * allocate (void)
 \( b \) bytes aligned to \( a \), \( b \) and \( a \) known at compile time
template<std::size_t b, std::size_t a = alignof( std::max_align_t )>
void deallocate (void *p)
 the memory \( p \) of allocate< b , a >() given back, to the free list of its page
void * allocate (std::size_t b, std::size_t a=alignof(std::max_align_t))
 \( b \) bytes aligned to \( a \), as allocate< b , a >() above
void deallocate (void *p, std::size_t b, std::size_t a=alignof(std::max_align_t))
 the memory \( p \) of allocate( b , a ) given back, to the free list of its page
std::size_t size (void) const
 the number of objects alive in the classes
std::size_t bytes (void) const
 the memory of the blocks of the classes, in bytes

Static public member functions

static constexpr bool pooled (std::size_t b, std::size_t a)
 true if a request of \( b \) bytes aligned to \( a \) takes a class, i.e., if \( 1 \le b \le M \) and \( a \le 16 \)

Static public attributes

static constexpr std::size_t GRAIN = 8
 the step of a class
static constexpr std::size_t ALIGN = 16
 the largest alignment
static constexpr std::size_t MAX = M
 the largest class
static constexpr std::size_t CLASSES = M / GRAIN
 the classes

Detailed description

template<std::size_t M = 256>
class ADS::PoolResource< M >

pools of the size classes of 8 bytes up to \( M \), for one thread at a time

Constructor and destructor documentation

◆ PoolResource() [1/2]

template<std::size_t M = 256>
ADS::PoolResource< M >::PoolResource ( void )

the empty resource

◆ PoolResource() [2/2]

template<std::size_t M = 256>
ADS::PoolResource< M >::PoolResource ( const PoolResource< M > & )
delete

no copy, since its objects and allocators point to it

◆ ~PoolResource()

template<std::size_t M = 256>
ADS::PoolResource< M >::~PoolResource ( )
default

frees the blocks; the objects still alive are not destroyed

Member function documentation

◆ allocate() [1/2]

template<std::size_t M = 256>
void * ADS::PoolResource< M >::allocate ( std::size_t b,
std::size_t a = alignof(std::max_align_t) )
nodiscard

\( b \) bytes aligned to \( a \), as allocate< b , a >() above

◆ allocate() [2/2]

template<std::size_t M = 256>
template<std::size_t b, std::size_t a = alignof( std::max_align_t )>
void * ADS::PoolResource< M >::allocate ( void )
nodiscard

\( b \) bytes aligned to \( a \), \( b \) and \( a \) known at compile time

In pseudocode (the free lists by page of Leijen et al., beyond the book), \( c \) the class of the request:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{allocate}( b , a ) \cr 2 & \quad \textbf{if}\ 1 \le b \le M\ \textbf{and}\ a \le 16 \ \textbf{then} \cr 3 & \qquad c \gets \lceil b / 8 \rceil - 1 \text{, or } 2 \lceil b / 16 \rceil - 1 \text{ if } a > 8 \cr 4 & \qquad \textbf{return}\ \text{a slot of the current page of } c \quad \triangleright\ \text{see PageHeap} \cr 5 & \quad \textbf{return}\ \text{the memory of operator new} \end{array}} \]

◆ bytes()

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::bytes ( void ) const
nodiscard

the memory of the blocks of the classes, in bytes

◆ deallocate() [1/2]

template<std::size_t M = 256>
template<std::size_t b, std::size_t a = alignof( std::max_align_t )>
void ADS::PoolResource< M >::deallocate ( void * p)

the memory \( p \) of allocate< b , a >() given back, to the free list of its page

Precondition
\( p \) was given by allocate< b , a >()

◆ deallocate() [2/2]

template<std::size_t M = 256>
void ADS::PoolResource< M >::deallocate ( void * p,
std::size_t b,
std::size_t a = alignof(std::max_align_t) )

the memory \( p \) of allocate( b , a ) given back, to the free list of its page

Precondition
\( p \) was given by allocate( b , a )

◆ operator=()

template<std::size_t M = 256>
PoolResource & ADS::PoolResource< M >::operator= ( const PoolResource< M > & )
delete

no copy, since its objects and allocators point to it

◆ pooled()

template<std::size_t M = 256>
constexpr bool ADS::PoolResource< M >::pooled ( std::size_t b,
std::size_t a )
inlinestaticnodiscardconstexpr

true if a request of \( b \) bytes aligned to \( a \) takes a class, i.e., if \( 1 \le b \le M \) and \( a \le 16 \)

◆ size()

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::size ( void ) const
nodiscard

the number of objects alive in the classes

Member data documentation

◆ ALIGN

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::ALIGN = 16
staticconstexpr

the largest alignment

◆ CLASSES

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::CLASSES = M / GRAIN
staticconstexpr

the classes

◆ GRAIN

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::GRAIN = 8
staticconstexpr

the step of a class

◆ MAX

template<std::size_t M = 256>
std::size_t ADS::PoolResource< M >::MAX = M
staticconstexpr

the largest class


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