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

#include <nda/mem/allocators.hpp>

Detailed Description

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

Custom allocator that allocates a bucket of memory on the heap consisting of 64 chunks.

The allocator keeps track of which chunks are free using a bitmask. Once all chunks have been allocated, it will call std::abort on any further allocation requests.

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

Definition at line 137 of file allocators.hpp.

Public Member Functions

 bucket ()=default
 Default constructor.
 
 bucket (bucket &&)=default
 Default move constructor.
 
 bucket (bucket const &)=delete
 Deleted copy constructor.
 
blk_t allocate (size_t s) noexcept
 Allocate a chunk of memory in the bucket and update the bitmask.
 
blk_t allocate_zero (size_t s) noexcept
 Allocate a chunk of memory in the bucket, set it to zero and update the bitmask.
 
const char * data () const noexcept
 Get a pointer to the start of the bucket.
 
void deallocate (blk_t b) noexcept
 Deallocate a chunk of memory from the bucket by simply resetting the bitmask.
 
bool empty () const noexcept
 Check if the bucket is empty.
 
bool is_full () const noexcept
 Check if the bucket is full.
 
auto mask () const noexcept
 Get the bitmask of the bucket.
 
bucketoperator= (bucket &&)=default
 Default move assignment operator.
 
bucketoperator= (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 the bucket.
 

Static Public Attributes

static constexpr auto address_space = Host
 Only Host nda::mem::AddressSpace is supported for this allocator.
 
static constexpr int TotalChunkSize = 64 * ChunkSize
 Total size of the bucket in bytes.
 

Member Function Documentation

◆ allocate()

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

Allocate a chunk of memory in the bucket and update the bitmask.

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

Definition at line 179 of file allocators.hpp.

◆ allocate_zero()

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

Allocate a chunk of memory in the bucket, set it to zero and update the bitmask.

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

Definition at line 202 of file allocators.hpp.

◆ data()

template<int ChunkSize>
const char * nda::mem::bucket< ChunkSize >::data ( ) const
inlinenodiscardnoexcept

Get a pointer to the start of the bucket.

Returns
Pointer to the chunk with the lowest memory address.

Definition at line 236 of file allocators.hpp.

◆ deallocate()

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

Deallocate a chunk of memory from the bucket by simply resetting the bitmask.

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

Definition at line 212 of file allocators.hpp.

◆ empty()

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

Check if the bucket is empty.

Returns
True if all chunks are free, i.e. the bitmask is all ones.

Definition at line 230 of file allocators.hpp.

◆ is_full()

template<int ChunkSize>
bool nda::mem::bucket< ChunkSize >::is_full ( ) const
inlinenodiscardnoexcept

Check if the bucket is full.

Returns
True if there are no free chunks left, i.e. the bitmask is all zeros.

Definition at line 224 of file allocators.hpp.

◆ mask()

template<int ChunkSize>
auto nda::mem::bucket< ChunkSize >::mask ( ) const
inlinenodiscardnoexcept

Get the bitmask of the bucket.

Returns
Bitmask in the form of a uint64_t.

Definition at line 242 of file allocators.hpp.

◆ owns()

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

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

Parameters
bnda::mem::blk_t memory block.
Returns
True if the memory block is owned by the bucket.

Definition at line 250 of file allocators.hpp.


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