template<typename T, size_t Size>
struct nda::mem::handle_sso< T, Size >
A handle for a memory block on the heap or stack depending on the size of the data.
If the size of the data is less than or equal to the template parameter Size
, the data is stored on the stack, otherwise it is stored on the heap (nda::mem::mallocator is used to allocate/deallocate memory on the heap).
It simulates the small string optimization (SSO) for strings.
- Note
- This handle only works with the
Host
nda::mem::AddressSpace.
- Template Parameters
-
T | Value type of the data. |
Size | Max. size of the data to store on the stack (number of elements). |
Definition at line 492 of file handle.hpp.
|
| handle_sso () |
| Default constructor.
|
|
template<OwningHandle< value_type > H> |
| handle_sso (H const &h) |
| Construct a handle by making a deep copy of the data from another owning handle.
|
|
| handle_sso (handle_sso &&h) noexcept |
| Move constructor either copies the heap pointers or makes a deep copy of the stack data.
|
|
| handle_sso (handle_sso const &h) |
| Copy construct a handle by making a deep copy of the data from the source handle.
|
|
| handle_sso (long size) |
| Construct a handle for the data of a given size and initialize it depending on the value type.
|
|
| handle_sso (long size, do_not_initialize_t) |
| Construct a handle for the data of a given size and do not initialize it.
|
|
| handle_sso (long size, init_zero_t) |
| Construct a handle for the data of a given size and initialize it to zero (only for scalar and complex types).
|
|
| ~handle_sso () noexcept |
| Destructor for the handle.
|
|
T * | data () const noexcept |
| Get a pointer to the stored data.
|
|
bool | is_null () const noexcept |
| Check if the handle is in a null state.
|
|
bool | on_heap () const |
| Check if the data is/should be stored on the heap.
|
|
handle_sso & | operator= (handle_sso &&h) noexcept |
| Move assignment operator first releases the resources held by the current handle and then either copies the heap pointers or makes a deep copy of the stack data.
|
|
handle_sso & | operator= (handle_sso const &h) |
| Copy assignment operator first cleans up the current handle and then makes a deep copy of the data 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.
|
|
template<typename T , size_t Size>
Destructor for the handle.
For non-trivial objects, it explicitly calls their destructors. Additionally, it deallocates the memory if it is stored on the heap and resets the handle to its null state.
Definition at line 535 of file handle.hpp.
template<typename T , size_t Size>
Construct a handle by making a deep copy of the data from another owning handle.
Depending on the size, the memory of the data is either allocated on the heap or on the stack.
- Parameters
-
Definition at line 620 of file handle.hpp.
template<typename T , size_t Size>
Construct a handle for the data of a given size and initialize it to zero (only for scalar and complex types).
Depending on the size, the memory of the data is either allocated on the heap or on the stack.
- Parameters
-
size | Size of the data (number of elements). |
Definition at line 656 of file handle.hpp.
template<typename T , size_t Size>
Move assignment operator first releases the resources held by the current handle and then either copies the heap pointers or makes a deep copy of the stack data.
In both cases, it resets the source handle to a null state.
- Parameters
-
Definition at line 563 of file handle.hpp.