nlib
nn::nlib::DynamicAlignedStorage Class Referencefinal

A class for obtaining aligned memory. More...

#include "nn/nlib/DynamicAlignedStorage.h"

Public Member Functions

errno_t Init (size_t size, size_t align) noexcept
 Allocates memory. More...
 
void * Get () noexcept
 Returns a pointer to the allocated region. More...
 
Basic Member Functions
constexpr DynamicAlignedStorage () noexcept
 Instantiates the object with default parameters (default constructor).
 
 DynamicAlignedStorage (DynamicAlignedStorage &&rhs) noexcept
 Instantiates the object (move constructor). This function is useful when using C++11.
 
DynamicAlignedStorageoperator= (DynamicAlignedStorage &&rhs) noexcept
 Move assignment operator. This function is useful when using C++11.
 
 DynamicAlignedStorage (DynamicAlignedStorage &rhs, move_tag) noexcept
 Corresponds to a move constructor.
 
DynamicAlignedStorageassign (DynamicAlignedStorage &rhs, move_tag) noexcept
 Corresponds to a move assignment operator.
 
void swap (DynamicAlignedStorage &rhs) noexcept
 Swaps objects. More...
 
 ~DynamicAlignedStorage () noexcept
 Destructor.
 

Detailed Description

A class for obtaining aligned memory.

Description
Although an alignment can be specified by using std::aligned_storage or alignas, whether large alignments are supported or not depends on the environment. To use memory with a large alignment, you must allocate memory dynamically. This class is implemented by wrapping nlib_memalign() for OSs other than Windows and by wrapping _aligned_malloc() for Windows.
Sample code
e = storage.Init(64 * 1024, 64); // 64 kbytes, 64 bytes aligned
if (nlib_is_error(e)) {
// ERROR
}
void* ptr = storage.Get(); // ptr is what you want

Definition at line 24 of file DynamicAlignedStorage.h.

Member Function Documentation

◆ Get()

nn::nlib::DynamicAlignedStorage::Get ( )
inlinenoexcept

Returns a pointer to the allocated region.

Returns
A pointer to the allocated region.

Definition at line 84 of file DynamicAlignedStorage.h.

◆ Init()

nn::nlib::DynamicAlignedStorage::Init ( size_t  size,
size_t  align 
)
inlinenoexcept

Allocates memory.

Parameters
[in]sizeSpecifies the size of the region to be allocated.
[in]alignSpecifies the alignment of the region to be allocated.
Return values
0Success.
EINVALThe alignment was not a power of two.
ENOMEMMemory allocation has failed.

Definition at line 60 of file DynamicAlignedStorage.h.

◆ swap()

nn::nlib::DynamicAlignedStorage::swap ( DynamicAlignedStorage rhs)
inlinenoexcept

Swaps objects.

Deprecated:
This function will be deleted in a future release.

Definition at line 55 of file DynamicAlignedStorage.h.


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