74#ifndef __ADS_ObjectPool
75 #define __ADS_ObjectPool
106template<
class T ,
class A = HugePageAllocator< T > >
115 explicit ObjectPool( std::size_t n = std::size_t( 1 ) << 24 ,
116 const A & alloc = A() );
178 template<
class... Args >
230 [[nodiscard]]
bool fresh(
const T * p )
const;
233 [[nodiscard]] std::size_t
size(
void )
const;
236 [[nodiscard]] std::size_t
bytes(
void )
const;
254 alignas( T )
unsigned char object[
sizeof( T ) ];
264 static constexpr std::size_t H =
265 (
sizeof( Block ) +
sizeof( Slot ) - 1 ) /
sizeof( Slot );
268 typename std::allocator_traits< A >::template rebind_alloc< Slot >;
271 void release(
void )
noexcept;
279 Slot * f_free =
nullptr;
280 Slot * f_next =
nullptr;
281 Slot * f_end =
nullptr;
282 Block * f_last =
nullptr;
283 Block * f_reuse =
nullptr;
285 std::size_t f_size = 0;
298#include "ADS/memory/impl/ObjectPool.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
void free(T *x)
destroys and keeps its slot for the next make()
ObjectPool & operator=(ObjectPool &&other) noexcept
the slots of other, which is left empty, after those of this pool are freed
allocator_type get_allocator(void) const
the allocator of the blocks
Definition ObjectPool.h:242
bool fresh(const T *p) const
whether is a slot given in the current epoch, alive or freed, in time linear in the blocks: false fo...
void adopt(ObjectPool &other) noexcept
the blocks of other taken by this pool, with the objects alive in them, other left empty: the objects...
ObjectPool(ObjectPool &&other) noexcept
the slots of other, which is left empty; its objects stay where they are
std::size_t size(void) const
the number of objects alive
std::size_t bytes(void) const
the memory of the blocks, in bytes
void clear(void) noexcept
all the objects and the free slots dropped, with no destructor called, and the blocks kept for the ne...
A allocator_type
the type of the allocator
Definition ObjectPool.h:239
void swap(ObjectPool &other) noexcept
the slots of this pool and of other exchanged
~ObjectPool()
frees the blocks; the objects still alive are not destroyed
T * allocate(void)
the raw slot of an object, not built, as std::allocator gives it: the caller builds the object in it ...
ObjectPool(const ObjectPool &)=delete
no copy, since its objects are reached by their addresses
T * make(Args &&... args)
a new object built from args, in the slot freed last if any; with no args the object is value-initial...
void deallocate(T *x)
keeps the slot of , whose object is already destroyed (or was never built), for the next make() or al...
ObjectPool(std::size_t n=std::size_t(1)<< 24, const A &alloc=A())
the empty pool whose blocks grow up to slots, taken from alloc
ObjectPool & operator=(const ObjectPool &)=delete
no copy, since its objects are reached by their addresses
#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