TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::mem::segregator< Threshold, A, B >

#include <nda/mem/allocators.hpp>

Detailed Description

template<size_t Threshold, Allocator A, Allocator B>
class nda::mem::segregator< Threshold, A, B >

Custom allocator that dispatches memory allocation to one of two allocators based on the size of the memory block to be allocated.

Note
Only works if both allocators have the same nda::mem::AddressSpace.
Template Parameters
ThresholdSize in bytes that determines which allocator to use.
Anda::mem::Allocator for small memory blocks.
Bnda::mem::Allocator for big memory blocks.

Definition at line 391 of file allocators.hpp.

Public Member Functions

 segregator ()=default
 Default constructor.
 
 segregator (segregator &&)=default
 Default move constructor.
 
 segregator (segregator const &)=delete
 Deleted copy constructor.
 
blk_t allocate (size_t s) noexcept
 Allocate memory using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.
 
blk_t allocate_zero (size_t s) noexcept
 Allocate memory and set the memory to zero using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.
 
void deallocate (blk_t b) noexcept
 Deallocate memory using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.
 
segregatoroperator= (segregator &&)=default
 Default move assignment operator.
 
segregatoroperator= (segregator 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 allocator.
 

Static Public Attributes

static constexpr auto address_space = A::address_space
 nda::mem::AddressSpace in which the memory is allocated.
 

Member Function Documentation

◆ allocate()

template<size_t Threshold, Allocator A, Allocator B>
blk_t nda::mem::segregator< Threshold, A, B >::allocate ( size_t s)
inlinenoexcept

Allocate memory using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.

Parameters
sSize in bytes of the memory to allocate.
Returns
nda::mem::blk_t memory block.

Definition at line 426 of file allocators.hpp.

◆ allocate_zero()

template<size_t Threshold, Allocator A, Allocator B>
blk_t nda::mem::segregator< Threshold, A, B >::allocate_zero ( size_t s)
inlinenoexcept

Allocate memory and set the memory to zero using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.

Parameters
sSize in bytes of the memory to allocate.
Returns
nda::mem::blk_t memory block.

Definition at line 435 of file allocators.hpp.

◆ deallocate()

template<size_t Threshold, Allocator A, Allocator B>
void nda::mem::segregator< Threshold, A, B >::deallocate ( blk_t b)
inlinenoexcept

Deallocate memory using the small allocator if the size is less than or equal to the Threshold, otherwise use the big allocator.

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

Definition at line 443 of file allocators.hpp.

◆ owns()

template<size_t Threshold, Allocator A, Allocator B>
bool nda::mem::segregator< Threshold, A, B >::owns ( blk_t b) const
inlinenodiscardnoexcept

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

Parameters
bnda::mem::blk_t memory block.
Returns
True if one of the two allocators owns the memory block.

Definition at line 451 of file allocators.hpp.


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