an arena of objects of type T in blocks of \( n \)
More...
#include <ADS/memory/Arena.h>
|
| | Arena (std::size_t n=std::size_t(1)<< 12, const A &alloc=A()) |
| | the empty arena whose blocks hold \( n \) objects, taken from alloc
|
| | Arena (const Arena &)=delete |
| | no copy, since the objects are reached by their addresses
|
| Arena & | operator= (const Arena &)=delete |
| | no copy, since the objects are reached by their addresses
|
| | ~Arena () |
| | destroys all the objects and frees the blocks
|
| template<class... Args> |
| T * | make (Args &&... args) |
| | a new object built from args, whose address never changes in the epoch; with no args the object is value-initialized, T(), in every epoch and on every place, so that an object of trivial type is all zeros whatever the place held in an old epoch
|
| void | clear (void) noexcept |
| | all the objects destroyed and the blocks kept for the next ones, the first of which goes to the first place of the first block: a new epoch, in which no object of the old ones survives
|
| bool | fresh (const T *p) const |
| | whether \( p \) is the address of an object made in the current epoch, in time linear in the blocks: false for a pointer of an old epoch whose place has not been given again, true for one whose place has
|
| std::size_t | size (void) const |
| | the number of objects made in the epoch
|
| std::size_t | bytes (void) const |
| | the memory of the blocks, in bytes, those kept for the epoch included
|
| iterator | begin (void) |
| | the first object made
|
| iterator | end (void) |
| | past the last object made
|
| const_iterator | begin (void) const |
| | the first object made, constant
|
| const_iterator | end (void) const |
| | past the last object made, constant
|
| const_iterator | cbegin (void) const |
| | the first object made, constant
|
| const_iterator | cend (void) const |
| | past the last object made, constant
|
template<class T, class A = std::allocator< T >>
class ADS::Arena< T, A >
an arena of objects of type T in blocks of \( n \)
◆ const_iterator
template<class T, class A = std::allocator< T >>
◆ const_reference
template<class T, class A = std::allocator< T >>
| using ADS::Arena< T, A >::const_reference = const T & |
◆ difference_type
template<class T, class A = std::allocator< T >>
| using ADS::Arena< T, A >::difference_type = std::ptrdiff_t |
◆ iterator
template<class T, class A = std::allocator< T >>
◆ reference
template<class T, class A = std::allocator< T >>
◆ size_type
template<class T, class A = std::allocator< T >>
◆ value_type
template<class T, class A = std::allocator< T >>
◆ Arena() [1/2]
template<class T, class A = std::allocator< T >>
| ADS::Arena< T, A >::Arena |
( |
std::size_t | n = std::size_t(1)<< 12, |
|
|
const A & | alloc = A() ) |
|
explicit |
the empty arena whose blocks hold \( n \) objects, taken from alloc
- Precondition
- \( n \ge 1 \)
◆ Arena() [2/2]
template<class T, class A = std::allocator< T >>
| ADS::Arena< T, A >::Arena |
( |
const Arena< T, A > & | | ) |
|
|
delete |
no copy, since the objects are reached by their addresses
◆ ~Arena()
template<class T, class A = std::allocator< T >>
destroys all the objects and frees the blocks
◆ begin() [1/2]
template<class T, class A = std::allocator< T >>
◆ begin() [2/2]
template<class T, class A = std::allocator< T >>
the first object made, constant
◆ bytes()
template<class T, class A = std::allocator< T >>
| std::size_t ADS::Arena< T, A >::bytes |
( |
void | | ) |
const |
|
nodiscard |
the memory of the blocks, in bytes, those kept for the epoch included
◆ cbegin()
template<class T, class A = std::allocator< T >>
the first object made, constant
◆ cend()
template<class T, class A = std::allocator< T >>
past the last object made, constant
◆ clear()
template<class T, class A = std::allocator< T >>
all the objects destroyed and the blocks kept for the next ones, the first of which goes to the first place of the first block: a new epoch, in which no object of the old ones survives
In pseudocode (beyond the book), \( \beta \) the blocks and \( c \) the index of the block in use:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{clear}() \cr
2 & \quad \textbf{if}\ T \text{ has a destructor}\ \textbf{then}
\ \text{destroy the objects of the blocks } 0 , \ldots , c \cr
3 & \quad \textbf{if}\ \beta > 0\ \textbf{then}\ c \gets 0;
\ \mathit{used} \gets 0 \cr
4 & \quad \mathit{size} \gets 0
\end{array}}
\]
- Precondition
- no other thread accesses an object of the arena: each of its accesses happens before the call
◆ end() [1/2]
template<class T, class A = std::allocator< T >>
past the last object made
◆ end() [2/2]
template<class T, class A = std::allocator< T >>
past the last object made, constant
◆ fresh()
template<class T, class A = std::allocator< T >>
| bool ADS::Arena< T, A >::fresh |
( |
const T * | p | ) |
const |
|
nodiscard |
whether \( p \) is the address of an object made in the current epoch, in time linear in the blocks: false for a pointer of an old epoch whose place has not been given again, true for one whose place has
◆ make()
template<class T, class A = std::allocator< T >>
template<class... Args>
a new object built from args, whose address never changes in the epoch; with no args the object is value-initialized, T(), in every epoch and on every place, so that an object of trivial type is all zeros whatever the place held in an old epoch
In pseudocode (the arena of Hanson, beyond the book), with \( \mathit{used} \) the objects of the block \( c \) in use and \( \beta \) the blocks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{make}( \mathit{args} ) \cr
2 & \quad \textbf{if}\ \text{there is no block}\ \textbf{or}
\ \mathit{used} = n\ \textbf{then} \cr
3 & \qquad \textbf{if}\ c + 1 < \beta\ \textbf{then}\ c \gets c + 1
\quad \triangleright\ \text{a block of an old epoch} \cr
4 & \qquad \textbf{else}\ \text{append a block of } n \text{ places}
\text{ from the allocator};\ c \gets \beta - 1 \cr
5 & \qquad \mathit{used} \gets 0 \cr
6 & \quad p \gets \text{the place } \mathit{used} \text{ of the}
\text{ block } c;\ \text{build the object in } p \cr
7 & \quad \mathit{used} \gets \mathit{used} + 1;\ \textbf{return}\ p
\end{array}}
\]
◆ operator=()
template<class T, class A = std::allocator< T >>
no copy, since the objects are reached by their addresses
◆ size()
template<class T, class A = std::allocator< T >>
| std::size_t ADS::Arena< T, A >::size |
( |
void | | ) |
const |
|
nodiscard |
the number of objects made in the epoch
The documentation for this class was generated from the following file: