pools of the size classes of 8 bytes up to \( M \), for one thread at a time
More...
#include <ADS/memory/PoolAllocator.h>
|
| | 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 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 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
|
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
◆ PoolResource() [1/2]
template<std::size_t M = 256>
◆ PoolResource() [2/2]
template<std::size_t M = 256>
no copy, since its objects and allocators point to it
◆ ~PoolResource()
template<std::size_t M = 256>
frees the blocks; the objects still alive are not destroyed
◆ 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 )>
\( 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>
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 )>
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>
no copy, since its objects and allocators point to it
◆ pooled()
template<std::size_t M = 256>
|
|
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>
the number of objects alive in the classes
◆ ALIGN
template<std::size_t M = 256>
◆ CLASSES
template<std::size_t M = 256>
◆ GRAIN
template<std::size_t M = 256>
◆ MAX
template<std::size_t M = 256>
The documentation for this class was generated from the following file: