an arena of bytes in blocks of \( n \), the resource of a PoolAllocator
More...
#include <ADS/memory/Arena.h>
|
| | ArenaResource (std::size_t n=std::size_t(1)<< 16, const A &alloc=A()) |
| | the empty resource whose blocks hold \( n \) bytes, taken from alloc
|
| | ArenaResource (const ArenaResource &)=delete |
| | no copy, since its allocators point to it
|
| ArenaResource & | operator= (const ArenaResource &)=delete |
| | no copy, since its allocators point to it
|
| | ~ArenaResource () |
| | 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 *) noexcept |
| | nothing: the bytes go back with the blocks
|
| void * | allocate (std::size_t b, std::size_t a=alignof(std::max_align_t)) |
| | \( b \) bytes aligned to \( a \), in the current block or in a new one
|
| void | deallocate (void *, std::size_t, std::size_t=alignof(std::max_align_t)) noexcept |
| | nothing: the bytes go back with the blocks
|
| void | release (void) noexcept |
| | all the blocks given back to the allocator: the memory given so far is no longer to be used
|
| std::size_t | bytes (void) const |
| | the memory of the blocks, in bytes
|
| std::size_t | size (void) const |
| | the number of requests served since the construction or release()
|
template<class A = std::allocator< std::max_align_t >>
class ADS::ArenaResource< A >
an arena of bytes in blocks of \( n \), the resource of a PoolAllocator
◆ ArenaResource() [1/2]
template<class A = std::allocator< std::max_align_t >>
| ADS::ArenaResource< A >::ArenaResource |
( |
std::size_t | n = std::size_t(1)<< 16, |
|
|
const A & | alloc = A() ) |
|
explicit |
the empty resource whose blocks hold \( n \) bytes, taken from alloc
- Precondition
- \( n \ge 1 \)
◆ ArenaResource() [2/2]
template<class A = std::allocator< std::max_align_t >>
no copy, since its allocators point to it
◆ ~ArenaResource()
template<class A = std::allocator< std::max_align_t >>
frees the blocks; the objects still alive are not destroyed
◆ allocate() [1/2]
template<class A = std::allocator< std::max_align_t >>
| void * ADS::ArenaResource< A >::allocate |
( |
std::size_t | b, |
|
|
std::size_t | a = alignof(std::max_align_t) ) |
|
nodiscard |
\( b \) bytes aligned to \( a \), in the current block or in a new one
In pseudocode (the arena of Hanson, beyond the book), with \( [ \mathit{next} , \mathit{end} ) \) the free bytes of the current block:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{allocate}( b , a ) \cr
2 & \quad p \gets \mathit{next} \text{ rounded up to a multiple of }
a \cr
3 & \quad \textbf{if}\ p + b > \mathit{end}\ \textbf{then}
\ \text{take a block of } \max( n , b + a ) \text{ bytes};\ p
\gets \text{its first byte aligned to } a \cr
4 & \quad \mathit{next} \gets p + b;\ \textbf{return}\ p
\end{array}}
\]
- Precondition
- \( a \) is a power of 2
- Exceptions
-
| std::bad_alloc | if a block of \( b + a \) bytes does not fit in a std::size_t, or if the allocator throws it; the resource is then as it was |
◆ allocate() [2/2]
template<class A = std::allocator< std::max_align_t >>
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
◆ bytes()
template<class A = std::allocator< std::max_align_t >>
the memory of the blocks, in bytes
◆ deallocate() [1/2]
template<class A = std::allocator< std::max_align_t >>
template<std::size_t b, std::size_t a = alignof( std::max_align_t )>
nothing: the bytes go back with the blocks
◆ deallocate() [2/2]
template<class A = std::allocator< std::max_align_t >>
| void ADS::ArenaResource< A >::deallocate |
( |
void * | , |
|
|
std::size_t | , |
|
|
std::size_t | = alignof( std::max_align_t ) ) |
|
inlinenoexcept |
nothing: the bytes go back with the blocks
◆ operator=()
template<class A = std::allocator< std::max_align_t >>
no copy, since its allocators point to it
◆ release()
template<class A = std::allocator< std::max_align_t >>
all the blocks given back to the allocator: the memory given so far is no longer to be used
◆ size()
template<class A = std::allocator< std::max_align_t >>
the number of requests served since the construction or release()
The documentation for this class was generated from the following file: