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

#include <nda/mem/handle.hpp>

Detailed Description

template<typename T, Allocator A = mallocator<>>
struct nda::mem::handle_heap< T, A >

A handle for a memory block on the heap.

By default it uses nda::mem::mallocator to allocate/deallocate memory.

Template Parameters
TValue type of the data.
Anda::mem::Allocator type.

Definition at line 99 of file handle.hpp.

Public Types

using allocator_type = A
 nda::mem::Allocator type.
 
using value_type = T
 Value type of the data.
 

Public Member Functions

 handle_heap ()=default
 Default constructor leaves the handle in a null state (nullptr and size 0).
 
template<OwningHandle< value_type > H>
 handle_heap (H const &h)
 Construct a handle by making a deep copy of the data from another handle.
 
 handle_heap (handle_heap &&h) noexcept
 Move constructor simply copies the pointers and size and resets the source handle to a null state.
 
 handle_heap (handle_heap const &h)
 Copy constructor makes a deep copy of the data from another handle.
 
 handle_heap (long size)
 Construct a handle by allocating memory for the data of a given size and initializing it depending on the value type.
 
 handle_heap (long size, do_not_initialize_t)
 Construct a handle by allocating memory for the data of a given size but without initializing it.
 
 handle_heap (long size, init_zero_t)
 Construct a handle by allocating memory for the data of a given size and initializing it to zero.
 
 ~handle_heap () noexcept
 Destructor for the handle.
 
T * data () const noexcept
 Get a pointer to the stored data.
 
std::shared_ptr< void > get_sptr () const
 Get a shared pointer to the memory block.
 
bool is_null () const noexcept
 Check if the handle is in a null state.
 
handle_heapoperator= (handle_heap &&h) noexcept
 Move assignment operator first releases the resources held by the current handle and then moves the resources from the source to the current handle.
 
handle_heapoperator= (handle_heap const &h)
 Copy assignment operator utilizes the copy constructor and move assignment operator to make a deep copy of the data and size from the source handle.
 
template<Allocator AS>
handle_heapoperator= (handle_heap< T, AS > const &h)
 Assignment operator utilizes another constructor and move assignment to make a deep copy of the data and size from the source handle.
 
T const & operator[] (long i) const noexcept
 Subscript operator to access the data.
 
T & operator[] (long i) noexcept
 Subscript operator to access the data.
 
long size () const noexcept
 Get the size of the handle.
 

Static Public Attributes

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

Constructor & Destructor Documentation

◆ ~handle_heap()

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::~handle_heap ( )
inlinenoexcept

Destructor for the handle.

If the shared pointer is set, it does nothing. Otherwise, it explicitly calls the destructor of non-trivial objects and deallocates the memory.

Definition at line 165 of file handle.hpp.

◆ handle_heap() [1/6]

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::handle_heap ( handle_heap< T, A > && h)
inlinenoexcept

Move constructor simply copies the pointers and size and resets the source handle to a null state.

Parameters
hSource handle.

Definition at line 176 of file handle.hpp.

◆ handle_heap() [2/6]

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::handle_heap ( handle_heap< T, A > const & h)
inlineexplicit

Copy constructor makes a deep copy of the data from another handle.

Parameters
hSource handle.

Definition at line 206 of file handle.hpp.

◆ handle_heap() [3/6]

template<typename T , Allocator A = mallocator<>>
template<OwningHandle< value_type > H>
nda::mem::handle_heap< T, A >::handle_heap ( H const & h)
inlineexplicit

Construct a handle by making a deep copy of the data from another handle.

Template Parameters
Hnda::mem::OwningHandle type.
Parameters
hSource handle.

Definition at line 233 of file handle.hpp.

◆ handle_heap() [4/6]

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::handle_heap ( long size,
do_not_initialize_t  )
inline

Construct a handle by allocating memory for the data of a given size but without initializing it.

Parameters
sizeSize of the data (number of elements).

Definition at line 261 of file handle.hpp.

◆ handle_heap() [5/6]

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::handle_heap ( long size,
init_zero_t  )
inline

Construct a handle by allocating memory for the data of a given size and initializing it to zero.

Parameters
sizeSize of the data (number of elements).

Definition at line 273 of file handle.hpp.

◆ handle_heap() [6/6]

template<typename T , Allocator A = mallocator<>>
nda::mem::handle_heap< T, A >::handle_heap ( long size)
inline

Construct a handle by allocating memory for the data of a given size and initializing it depending on the value type.

The data is initialized as follows:

  • If T is std::complex and nda::mem::init_dcmplx is true, the data is initialized to zero.
  • If T is not trivial and not complex, the data is default constructed by placement new operator calls.
  • Otherwise, the data is not initialized.
Parameters
sizeSize of the data (number of elements).

Definition at line 292 of file handle.hpp.

Member Function Documentation

◆ data()

template<typename T , Allocator A = mallocator<>>
T * nda::mem::handle_heap< T, A >::data ( ) const
inlinenodiscardnoexcept

Get a pointer to the stored data.

Returns
Pointer to the start of the handled memory.

Definition at line 341 of file handle.hpp.

◆ get_sptr()

template<typename T , Allocator A = mallocator<>>
std::shared_ptr< void > nda::mem::handle_heap< T, A >::get_sptr ( ) const
inline

Get a shared pointer to the memory block.

Returns
A copy of the shared pointer stored in the current handle.

Definition at line 155 of file handle.hpp.

◆ is_null()

template<typename T , Allocator A = mallocator<>>
bool nda::mem::handle_heap< T, A >::is_null ( ) const
inlinenodiscardnoexcept

Check if the handle is in a null state.

Returns
True if the data is a nullptr (and the size is 0).

Definition at line 329 of file handle.hpp.

◆ operator=() [1/3]

template<typename T , Allocator A = mallocator<>>
handle_heap & nda::mem::handle_heap< T, A >::operator= ( handle_heap< T, A > && h)
inlinenoexcept

Move assignment operator first releases the resources held by the current handle and then moves the resources from the source to the current handle.

Parameters
hSource handle.

Definition at line 187 of file handle.hpp.

◆ operator=() [2/3]

template<typename T , Allocator A = mallocator<>>
handle_heap & nda::mem::handle_heap< T, A >::operator= ( handle_heap< T, A > const & h)
inline

Copy assignment operator utilizes the copy constructor and move assignment operator to make a deep copy of the data and size from the source handle.

Parameters
hSource handle.

Definition at line 221 of file handle.hpp.

◆ operator=() [3/3]

template<typename T , Allocator A = mallocator<>>
template<Allocator AS>
handle_heap & nda::mem::handle_heap< T, A >::operator= ( handle_heap< T, AS > const & h)
inline

Assignment operator utilizes another constructor and move assignment to make a deep copy of the data and size from the source handle.

Template Parameters
ASAllocator type of the source handle.
Parameters
hSource handle with a different allocator.

Definition at line 252 of file handle.hpp.

◆ operator[]() [1/2]

template<typename T , Allocator A = mallocator<>>
T const & nda::mem::handle_heap< T, A >::operator[] ( long i) const
inlinenodiscardnoexcept

Subscript operator to access the data.

Parameters
iIndex of the element to access.
Returns
Const reference to the element at the given index.

Definition at line 323 of file handle.hpp.

◆ operator[]() [2/2]

template<typename T , Allocator A = mallocator<>>
T & nda::mem::handle_heap< T, A >::operator[] ( long i)
inlinenodiscardnoexcept

Subscript operator to access the data.

Parameters
iIndex of the element to access.
Returns
Reference to the element at the given index.

Definition at line 315 of file handle.hpp.

◆ size()

template<typename T , Allocator A = mallocator<>>
long nda::mem::handle_heap< T, A >::size ( ) const
inlinenodiscardnoexcept

Get the size of the handle.

Returns
Number of elements of type T in the handled memory.

Definition at line 347 of file handle.hpp.


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