TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::mem::multi_bucket< ChunkSize >

#include <nda/mem/allocators.hpp>

Detailed Description

template<int ChunkSize>
class nda::mem::multi_bucket< ChunkSize >

Custom allocator that uses multiple nda::mem::bucket allocators.

It uses a std::vector of bucket allocators. When all buckets in the vector are full, it simply adds a new one at the end.

Note
Only works with Host nda::mem::AddressSpace.
Template Parameters
ChunkSizeSize of the chunks in bytes.

Definition at line 264 of file allocators.hpp.

Public Member Functions

 multi_bucket ()
 Default constructor.
 
 multi_bucket (multi_bucket &&)=default
 Default move constructor.
 
 multi_bucket (multi_bucket const &)=delete
 Deleted copy constructor.
 
blk_t allocate (size_t s) noexcept
 Allocate a chunk of memory in the current bucket or find a new one if the current one is full.
 
blk_t allocate_zero (size_t s) noexcept
 Allocate a chunk of memory in the current bucket or find a new one if the current one is full and set it to zero.
 
auto const & buckets () const noexcept
 Get the bucket vector.
 
void deallocate (blk_t b) noexcept
 Deallocate a chunk of memory from the bucket to which it belongs.
 
bool empty () const noexcept
 Check if the current allocator is empty.
 
multi_bucketoperator= (multi_bucket &&)=default
 Default move assignment operator.
 
multi_bucketoperator= (multi_bucket const &)=delete
 Deleted copy assignment operator.
 
bool owns (blk_t b) const noexcept
 Check if a given nda::mem::blk_t memory block is owned by allocator.
 

Static Public Attributes

static constexpr auto address_space = Host
 Only Host nda::mem::AddressSpace is supported for this allocator.
 

Member Function Documentation

◆ allocate()

template<int ChunkSize>
blk_t nda::mem::multi_bucket< ChunkSize >::allocate ( size_t s)
inlinenoexcept

Allocate a chunk of memory in the current bucket or find a new one if the current one is full.

Parameters
sSize in bytes of the returned memory block (has to be < ChunkSize).
Returns
nda::mem::blk_t memory block.

Definition at line 308 of file allocators.hpp.

◆ allocate_zero()

template<int ChunkSize>
blk_t nda::mem::multi_bucket< ChunkSize >::allocate_zero ( size_t s)
inlinenoexcept

Allocate a chunk of memory in the current bucket or find a new one if the current one is full and set it to zero.

Parameters
sSize in bytes of the returned memory block (has to be < ChunkSize).
Returns
nda::mem::blk_t memory block.

Definition at line 320 of file allocators.hpp.

◆ buckets()

template<int ChunkSize>
auto const & nda::mem::multi_bucket< ChunkSize >::buckets ( ) const
inlinenodiscardnoexcept

Get the bucket vector.

Returns
std::vector with all the bucket allocators currently in use.

Definition at line 365 of file allocators.hpp.

◆ deallocate()

template<int ChunkSize>
void nda::mem::multi_bucket< ChunkSize >::deallocate ( blk_t b)
inlinenoexcept

Deallocate a chunk of memory from the bucket to which it belongs.

If the bucket is empty after deallocation and it is not the only one, it is removed from the vector of buckets.

Parameters
bnda::mem::blk_t memory block to deallocate.

Definition at line 334 of file allocators.hpp.

◆ empty()

template<int ChunkSize>
bool nda::mem::multi_bucket< ChunkSize >::empty ( ) const
inlinenodiscardnoexcept

Check if the current allocator is empty.

Returns
True if there is only one bucket in the vector and it is empty.

Definition at line 359 of file allocators.hpp.

◆ owns()

template<int ChunkSize>
bool nda::mem::multi_bucket< ChunkSize >::owns ( blk_t b) const
inlinenodiscardnoexcept

Check if a given nda::mem::blk_t memory block is owned by allocator.

Parameters
bnda::mem::blk_t memory block.
Returns
True if the memory block is owned by one of the buckets.

Definition at line 373 of file allocators.hpp.


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