16 #ifndef INCLUDE_NN_NLIB_DYNAMICALIGNEDSTORAGE_H_ 17 #define INCLUDE_NN_NLIB_DYNAMICALIGNEDSTORAGE_H_ 20 #include "nn/nlib/Swap.h" 27 #ifdef __cpp_rvalue_references 29 : storage_(rhs.storage_) {
30 rhs.storage_ =
nullptr;
33 storage_ = rhs.storage_;
34 rhs.storage_ =
nullptr;
39 #ifdef NN_PLATFORM_CTR 40 : storage_(rhs.storage_), align_(rhs.align_)
42 : storage_(rhs.storage_)
45 rhs.storage_ =
nullptr;
48 #ifdef NN_PLATFORM_CTR 51 storage_ = rhs.storage_;
52 rhs.storage_ =
nullptr;
56 void* tmp = rhs.storage_;
57 rhs.storage_ = storage_;
61 if (align == 0)
return EINVAL;
62 if ((align & (align - 1)) != 0)
return EINVAL;
63 #ifdef NN_PLATFORM_CTR 65 #elif defined(_MSC_VER) 66 void* p = _aligned_malloc(size, align);
70 if (!p)
return ENOMEM;
72 #ifdef NN_PLATFORM_CTR 79 _aligned_free(storage_);
85 #ifndef NN_PLATFORM_CTR 88 uintptr_t pos = (
reinterpret_cast<uintptr_t
>(storage_) + (align_ - 1)) & ~(align_ - 1);
89 return reinterpret_cast<void*
>(pos);
95 #ifdef NN_PLATFORM_CTR 103 NLIB_DEFINE_STD_SWAP(NLIB_NS::DynamicAlignedStorage)
105 #endif // INCLUDE_NN_NLIB_DYNAMICALIGNEDSTORAGE_H_ DynamicAlignedStorage & operator=(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.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
errno_t Init(size_t size, size_t align) noexcept
Allocates memory.
DynamicAlignedStorage & assign(DynamicAlignedStorage &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
~DynamicAlignedStorage() noexcept
Destructor.
A class for obtaining aligned memory.
An empty structure indicating that an argument to a function needs to be moved.
void swap(DynamicAlignedStorage &rhs) noexcept
Swaps objects.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
void * Get() noexcept
Returns a pointer to the allocated region.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
A file that contains the configuration information for each development environment.
constexpr DynamicAlignedStorage() noexcept
Instantiates the object with default parameters (default constructor).
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
DynamicAlignedStorage(DynamicAlignedStorage &&rhs) noexcept
Instantiates the object (move constructor). This function is useful when using C++11.