Public Member Functions | Public Attributes | Private Member Functions | List of all members
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t Class Reference

Internal memory chunk; like a std::vector, but does not construct. More...

Public Member Functions

 MemoryChunk_t (Allocator_t &alloc, size_type n)
 
 MemoryChunk_t (const MemoryChunk_t &)=delete
 Can't copy. More...
 
 MemoryChunk_t (MemoryChunk_t &&)
 Move constructor. More...
 
 ~MemoryChunk_t ()
 
MemoryChunk_toperator= (const MemoryChunk_t &)=delete
 Can't assign. More...
 
MemoryChunk_toperator= (MemoryChunk_t &&)
 Move assignment. More...
 
size_type size () const
 Returns the number of elements in this pool. More...
 
size_type available () const
 Returns the number of free elements in this pool. More...
 
size_type used () const
 Returns the number of used elements in this pool. More...
 
bool full () const
 Returns whether the chunk is full. More...
 
pointer get ()
 Returns a pointer to a free item, or nullptr if none is available. More...
 
pointer get (size_t n)
 Returns a pointer to n free items, or nullptr if not available. More...
 

Public Attributes

Allocator_tallocator
 reference to the allocator to be used More...
 
pointer begin = nullptr
 start of the pool More...
 
pointer end = nullptr
 end of the pool More...
 
pointer free = nullptr
 first unused element of the pool More...
 

Private Member Functions

 MemoryChunk_t ()
 < Default constructor (does nothing) More...
 

Detailed Description

template<typename T>
class lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t

Internal memory chunk; like a std::vector, but does not construct.

Definition at line 324 of file BulkAllocator.h.

Constructor & Destructor Documentation

template<typename T>
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::MemoryChunk_t ( Allocator_t alloc,
size_type  n 
)
inline

Definition at line 333 of file BulkAllocator.h.

333  : allocator(&alloc)
334  {
335  begin = n? allocator->allocate(n): nullptr;
336  end = begin + n;
337  free = begin;
338  } // MemoryChunk_t()
Allocator_t * allocator
reference to the allocator to be used
std::void_t< T > n
template<typename T>
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::MemoryChunk_t ( const MemoryChunk_t )
delete

Can't copy.

template<typename T >
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::MemoryChunk_t ( MemoryChunk_t &&  from)

Move constructor.

Definition at line 393 of file BulkAllocator.h.

393  {
394  std::swap(allocator, from.allocator);
395  std::swap(begin, from.begin);
396  std::swap(end, from.end);
397  std::swap(free, from.free);
398  } // BulkAllocatorBase<T>::MemoryChunk_t::MemoryChunk_t(MemoryChunk_t&&)
Allocator_t * allocator
reference to the allocator to be used
void swap(Handle< T > &a, Handle< T > &b)
template<typename T>
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::~MemoryChunk_t ( )
inline

Definition at line 342 of file BulkAllocator.h.

342 { allocator->deallocate(begin, size()); }
Allocator_t * allocator
reference to the allocator to be used
size_type size() const
Returns the number of elements in this pool.
template<typename T>
lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::MemoryChunk_t ( )
inlineprivate

< Default constructor (does nothing)

Definition at line 374 of file BulkAllocator.h.

374 : allocator(nullptr) {}
Allocator_t * allocator
reference to the allocator to be used

Member Function Documentation

template<typename T>
size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::available ( ) const
inline

Returns the number of free elements in this pool.

Definition at line 352 of file BulkAllocator.h.

template<typename T>
bool lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::full ( ) const
inline

Returns whether the chunk is full.

Definition at line 358 of file BulkAllocator.h.

358 { return !available(); }
size_type available() const
Returns the number of free elements in this pool.
template<typename T>
pointer lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::get ( )
inline

Returns a pointer to a free item, or nullptr if none is available.

Definition at line 361 of file BulkAllocator.h.

361 { return (free != end)? free++: nullptr; }
template<typename T>
pointer lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::get ( size_t  n)
inline

Returns a pointer to n free items, or nullptr if not available.

Definition at line 364 of file BulkAllocator.h.

365  {
366  pointer ptr = free;
367  if ((free += n) <= end) return ptr;
368  free = ptr;
369  return nullptr;
370  }
std::void_t< T > n
template<typename T>
MemoryChunk_t& lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::operator= ( const MemoryChunk_t )
delete

Can't assign.

template<typename T >
BulkAllocatorBase< T >::MemoryChunk_t & lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::operator= ( MemoryChunk_t &&  from)

Move assignment.

Definition at line 402 of file BulkAllocator.h.

403  {
404  std::swap(allocator, from.allocator);
405  std::swap(begin, from.begin);
406  std::swap(end, from.end);
407  std::swap(free, from.free);
408  return *this;
409  } // BulkAllocatorBase<T>::MemoryChunk_t::operator= (MemoryChunk_t&&)
Allocator_t * allocator
reference to the allocator to be used
void swap(Handle< T > &a, Handle< T > &b)
template<typename T>
size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::size ( void  ) const
inline

Returns the number of elements in this pool.

Definition at line 349 of file BulkAllocator.h.

template<typename T>
size_type lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::used ( ) const
inline

Returns the number of used elements in this pool.

Definition at line 355 of file BulkAllocator.h.

355 { return free - begin; }

Member Data Documentation

template<typename T>
Allocator_t* lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::allocator

reference to the allocator to be used

Definition at line 326 of file BulkAllocator.h.

template<typename T>
pointer lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::begin = nullptr

start of the pool

Definition at line 328 of file BulkAllocator.h.

template<typename T>
pointer lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::end = nullptr

end of the pool

Definition at line 329 of file BulkAllocator.h.

template<typename T>
pointer lar::details::bulk_allocator::BulkAllocatorBase< T >::MemoryChunk_t::free = nullptr

first unused element of the pool

Constructor: allocates memory

Definition at line 330 of file BulkAllocator.h.


The documentation for this class was generated from the following file: