nlib
nn::nlib::DynamicAlignedStorage Class Referencefinal

A class for obtaining aligned memory. More...

#include "nn/nlib/DynamicAlignedStorage.h"

Public Member Functions

void * Get () noexcept
 Returns a pointer to the allocated region. More...
 
Constructor, Destructor, and Initialization
constexpr DynamicAlignedStorage () noexcept
 Instantiates the object with default parameters (default constructor).
 
 DynamicAlignedStorage (DynamicAlignedStorage &&rhs) noexcept
 Instantiates the object (move constructor).
 
DynamicAlignedStorageoperator= (DynamicAlignedStorage &&rhs) noexcept
 Move assignment operator.
 
 DynamicAlignedStorage (DynamicAlignedStorage &rhs, move_tag) noexcept
 Corresponds to a move constructor.
 
DynamicAlignedStorageassign (DynamicAlignedStorage &rhs, move_tag) noexcept
 Corresponds to a move assignment operator.
 
errno_t Init (size_t size, size_t align) noexcept
 Allocates memory. 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 is provided below.
errno_t e = storage.Init(64 * 1024, 64); // 64 kbytes, 64 bytes aligned
SUCCEED_IF(e == 0);
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 79 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 55 of file DynamicAlignedStorage.h.


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