LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 327 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 336 of file BulkAllocator.h.

References util::begin(), and n.

336  : allocator(&alloc)
337  {
338  begin = n ? allocator->allocate(n) : nullptr;
339  end = begin + n;
340  free = begin;
341  } // MemoryChunk_t()
Allocator_t * allocator
reference to the allocator to be used
Char_t n[5]
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 395 of file BulkAllocator.h.

References util::begin(), and util::end().

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

Definition at line 345 of file BulkAllocator.h.

References util::size().

345 { 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 377 of file BulkAllocator.h.

377 : 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 355 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 361 of file BulkAllocator.h.

361 { 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 364 of file BulkAllocator.h.

364 { 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 367 of file BulkAllocator.h.

References util::end().

368  {
369  pointer ptr = free;
370  if ((free += n) <= end) return ptr;
371  free = ptr;
372  return nullptr;
373  }
Char_t n[5]
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 404 of file BulkAllocator.h.

References util::begin(), and util::end().

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

Returns the number of elements in this pool.

Definition at line 352 of file BulkAllocator.h.

References util::begin().

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 358 of file BulkAllocator.h.

References util::begin().

358 { 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 329 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 331 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 332 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 333 of file BulkAllocator.h.


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