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

#include <nda/mem/allocators.hpp>

Detailed Description

template<Allocator A>
class nda::mem::leak_check< A >

Wrap an allocator to check for memory leaks.

It simply keeps track of the memory currently being used by the allocator, i.e. the total memory allocated minus the total memory deallocated, which should never be smaller than zero and should be exactly zero when the allocator is destroyed.

Template Parameters
Anda::mem::Allocator type to wrap.

Definition at line 464 of file allocators.hpp.

Inherits nda::mem::A.

Public Member Functions

 leak_check ()=default
 Default constructor.
 
 leak_check (leak_check &&)=default
 Default move constructor.
 
 leak_check (leak_check const &)=delete
 Deleted copy constructor.
 
 ~leak_check ()
 Destructor that checks for memory leaks.
 
blk_t allocate (size_t s)
 Allocate memory and update the total memory used.
 
blk_t allocate_zero (size_t s)
 Allocate memory, set it to zero and update the total memory used.
 
void deallocate (blk_t b) noexcept
 Deallocate memory and update the total memory used.
 
bool empty () const
 Check if the base allocator is empty.
 
long get_memory_used () const noexcept
 Get the total memory used by the base allocator.
 
leak_checkoperator= (leak_check &&)=default
 Default move assignment operator.
 
leak_checkoperator= (leak_check 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 base allocator.
 

Static Public Attributes

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

Constructor & Destructor Documentation

◆ ~leak_check()

template<Allocator A>
nda::mem::leak_check< A >::~leak_check ( )
inline

Destructor that checks for memory leaks.

In debug mode, it aborts the program if there is a memory leak.

Definition at line 491 of file allocators.hpp.

Member Function Documentation

◆ allocate()

template<Allocator A>
blk_t nda::mem::leak_check< A >::allocate ( size_t s)
inline

Allocate memory and update the total memory used.

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

Definition at line 506 of file allocators.hpp.

◆ allocate_zero()

template<Allocator A>
blk_t nda::mem::leak_check< A >::allocate_zero ( size_t s)
inline

Allocate memory, set it to zero and update the total memory used.

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

Definition at line 518 of file allocators.hpp.

◆ deallocate()

template<Allocator A>
void nda::mem::leak_check< A >::deallocate ( blk_t b)
inlinenoexcept

Deallocate memory and update the total memory used.

In debug mode, it aborts the program if the total memory used is smaller than zero.

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

Definition at line 529 of file allocators.hpp.

◆ empty()

template<Allocator A>
bool nda::mem::leak_check< A >::empty ( ) const
inlinenodiscard

Check if the base allocator is empty.

Returns
True if no memory is currently being used.

Definition at line 544 of file allocators.hpp.

◆ get_memory_used()

template<Allocator A>
long nda::mem::leak_check< A >::get_memory_used ( ) const
inlinenodiscardnoexcept

Get the total memory used by the base allocator.

Returns
The size of the memory which has been allocated and not yet deallocated.

Definition at line 558 of file allocators.hpp.

◆ owns()

template<Allocator A>
bool nda::mem::leak_check< A >::owns ( blk_t b) const
inlinenodiscardnoexcept

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

Parameters
bnda::mem::blk_t memory block.
Returns
True if the base allocator owns the memory block.

Definition at line 552 of file allocators.hpp.


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