103template<
class T ,
class A = std::allocator< T > >
111 explicit Arena( std::size_t n = std::size_t( 1 ) << 12 ,
112 const A & alloc = A() );
145 template<
class... Args >
172 [[nodiscard]]
bool fresh(
const T * p )
const;
175 [[nodiscard]] std::size_t
size(
void )
const;
178 [[nodiscard]] std::size_t
bytes(
void )
const;
188 template<
bool Const >
191 using Blocks =
const std::vector< T * > *;
201 using reference = std::conditional_t< Const , const T & , T & >;
203 using pointer = std::conditional_t< Const , const T * , T * >;
209 Iterator( Blocks B , std::size_t n , std::size_t i )
210 : f_B( B ) , f_n( n ) , f_i( i ) { }
214 requires( Const && ! K )
216 : f_B( o.f_B ) , f_n( o.f_n ) , f_i( o.f_i ) { }
225 const std::size_t j = f_i + std::size_t( k );
226 return( ( *f_B )[ j / f_n ][ j % f_n ] );
253 f_i += std::size_t( k );
258 f_i -= std::size_t( k );
283 Blocks f_B =
nullptr;
284 std::size_t f_n = 1 , f_i = 0;
300 return(
iterator( &f_blocks , f_n , 0 ) );
305 return(
iterator( &f_blocks , f_n , f_size ) );
330 [[nodiscard]] std::size_t used(
void )
const {
331 return( f_blocks.empty() ? 0 : std::size_t( f_place - f_blocks[ f_cur ] ) );
335 T * f_place =
nullptr;
337 std::size_t f_cur = 0;
338 std::size_t f_size = 0;
339 std::vector< T * > f_blocks;
350template<
class A = std::allocator< std::max_align_t > >
360 const A & alloc = A() );
372 template< std::
size_t b , std::
size_t a = alignof( std::max_align_t ) >
378 template< std::
size_t b , std::
size_t a = alignof( std::max_align_t ) >
403 std::size_t a =
alignof( std::max_align_t ) );
407 std::size_t =
alignof( std::max_align_t ) )
noexcept { }
414 [[nodiscard]] std::size_t
bytes(
void )
const {
return( f_bytes ); }
417 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
421 using Unit = std::max_align_t;
430 static constexpr std::size_t H =
431 (
sizeof( Block ) +
sizeof( Unit ) - 1 ) /
sizeof( Unit );
434 typename std::allocator_traits< A >::template rebind_alloc< Unit >;
436 unsigned char * f_next =
nullptr;
437 unsigned char * f_end =
nullptr;
438 Block * f_last =
nullptr;
440 std::size_t f_bytes = 0;
441 std::size_t f_size = 0;
454#include "ADS/memory/impl/Arena.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
~ArenaResource()
frees the blocks; the objects still alive are not destroyed
std::size_t bytes(void) const
the memory of the blocks, in bytes
Definition Arena.h:414
std::size_t size(void) const
the number of requests served since the construction or release()
Definition Arena.h:417
ArenaResource(const ArenaResource &)=delete
no copy, since its allocators point to it
void deallocate(void *) noexcept
nothing: the bytes go back with the blocks
Definition Arena.h:379
ArenaResource(std::size_t n=std::size_t(1)<< 16, const A &alloc=A())
the empty resource whose blocks hold bytes, taken from alloc
void release(void) noexcept
all the blocks given back to the allocator: the memory given so far is no longer to be used
void deallocate(void *, std::size_t, std::size_t=alignof(std::max_align_t)) noexcept
nothing: the bytes go back with the blocks
Definition Arena.h:406
void * allocate(std::size_t b, std::size_t a=alignof(std::max_align_t))
bytes aligned to , in the current block or in a new one
ArenaResource & operator=(const ArenaResource &)=delete
no copy, since its allocators point to it
void * allocate(void)
bytes aligned to , and known at compile time
Definition Arena.h:373
std::conditional_t< Const, const T *, T * > pointer
a pointer to an object, constant if Const
Definition Arena.h:203
Iterator(const Iterator< K > &o)
the constant iterator of the object of
Definition Arena.h:215
bool operator==(const Iterator &o) const
whether the two are at the same object
Definition Arena.h:278
Iterator & operator-=(difference_type k)
objects back
Definition Arena.h:257
reference operator[](difference_type k) const
the object places ahead: the index is at the place of the block
Definition Arena.h:224
friend Iterator operator+(Iterator a, difference_type k)
the iterator objects after
Definition Arena.h:262
Iterator & operator--(void)
the previous object
Definition Arena.h:235
std::ptrdiff_t difference_type
a distance in objects
Definition Arena.h:199
std::random_access_iterator_tag iterator_category
random access
Definition Arena.h:195
auto operator<=>(const Iterator &o) const
the order of the objects
Definition Arena.h:280
friend Iterator operator+(difference_type k, Iterator a)
the iterator objects after
Definition Arena.h:266
Iterator operator++(int)
the next object, the iterator before the step returned
Definition Arena.h:240
T value_type
the objects
Definition Arena.h:197
Iterator & operator++(void)
the next object
Definition Arena.h:230
Iterator operator--(int)
the previous object, the iterator before the step returned
Definition Arena.h:246
std::conditional_t< Const, const T &, T & > reference
a reference to an object, constant if Const
Definition Arena.h:201
pointer operator->(void) const
the address of the object
Definition Arena.h:221
Iterator(Blocks B, std::size_t n, std::size_t i)
the object of the vector of the blocks , of objects each
Definition Arena.h:209
friend difference_type operator-(const Iterator &a, const Iterator &b)
the number of objects from to
Definition Arena.h:274
Iterator(void)=default
an iterator of no arena
Iterator & operator+=(difference_type k)
objects ahead
Definition Arena.h:252
friend class Iterator
Definition Arena.h:287
reference operator*(void) const
the object
Definition Arena.h:219
friend Iterator operator-(Iterator a, difference_type k)
the iterator objects before
Definition Arena.h:270
std::size_t size(void) const
the number of objects made in the 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...
Arena & operator=(const Arena &)=delete
no copy, since the objects are reached by their addresses
iterator end(void)
past the last object made
Definition Arena.h:304
T * make(Args &&... args)
a new object built from args, whose address never changes in the epoch; with no args the object is va...
const_iterator end(void) const
past the last object made, constant
Definition Arena.h:314
std::size_t size_type
a number of objects
Definition Arena.h:291
const_iterator cend(void) const
past the last object made, constant
Definition Arena.h:322
Iterator< true > const_iterator
the constant iterator
Definition Arena.h:296
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
Definition Arena.h:299
Arena(std::size_t n=std::size_t(1)<< 12, const A &alloc=A())
the empty arena whose blocks hold objects, taken from alloc
~Arena()
destroys all the objects and frees the blocks
const T & const_reference
a constant one
Definition Arena.h:294
const_iterator cbegin(void) const
the first object made, constant
Definition Arena.h:319
T & reference
a reference to an object
Definition Arena.h:293
bool fresh(const T *p) const
whether is the address of an object made in the current epoch, in time linear in the blocks: false f...
std::ptrdiff_t difference_type
a distance in objects
Definition Arena.h:292
T value_type
the objects
Definition Arena.h:290
Arena(const Arena &)=delete
no copy, since the objects are reached by their addresses
Iterator< false > iterator
the iterator
Definition Arena.h:295
const_iterator begin(void) const
the first object made, constant
Definition Arena.h:309
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81