class
#include <Base/Memory.h>
Memory Memory-related utilities.
Public static functions
-
template<class T, std::static auto allocateAligned(std::
size_t alignment = alignof(T)> size_t size) -> Containers:: Array<T> - Allocate aligned memory and value-initialize it.
-
template<class T, std::static auto allocateAligned(Containers::
size_t alignment = alignof(T)> DefaultInitT, std:: size_t size) -> Containers:: Array<T> - Allocate aligned memory and default-initialize it.
-
template<class T, std::static auto allocateAligned(Containers::
size_t alignment = alignof(T)> ValueInitT, std:: size_t size) -> Containers:: Array<T> - Allocate aligned memory and value-initialize it.
-
template<class T, std::static auto allocateAligned(Containers::
size_t alignment = alignof(T)> NoInitT, std:: size_t size) -> Containers:: Array<T> - Allocate aligned memory and leave it uninitialized.
-
template<typename T, typename std::static auto loadUnaligned(const void* p) -> T constexpr noexcept
enable_if<std:: is_trivially_copyable<T>::value, int>::type = 0> - Returns a value of given size from unaligned pointer.
-
template<typename T, typename std::static void storeUnaligned(void* p, T v) constexpr noexcept
enable_if<std:: is_trivially_copyable<T>::value, int>::type = 0> - Stores a value of given size to unaligned pointer.
Constructors, destructors, conversion operators
Function documentation
template<class T, std:: size_t alignment = alignof(T)>
static Containers:: Array<T> Death:: Memory:: allocateAligned(std:: size_t size)
Allocate aligned memory and value-initialize it.
Template parameters | |
---|---|
T | Type of the returned array |
alignment | Allocation alignment, in bytes |
Parameters | |
size | Count of T items to allocate. If 0 , no allocation is done. |
Compared to the classic C std::new
that commonly aligns only to 2*sizeof(void*)
, this function returns "overaligned" allocations, which is mainly useful for efficient SIMD operations.
The alignment is implicitly alignof(T)
, but can be overridden with the alignment
template parameter. When specified explicitly, it is expected to be a power-of-two value, at most 256
bytes and the total byte size being a multiple of the alignment.
The returned pointer is always aligned to at least the desired value, but the alignment can be also higher. For example, allocating a 2 MB buffer may result in it being aligned to the whole memory page, or small alignment values could get rounded up to the default 2*sizeof(void*)
alignment.
Array initialization
Like with Containers::
- allocateAligned(Containers::
DefaultInitT, std:: size_t) leaves trivial types uninitialized and calls the default constructor elsewhere. Because of the differing behavior for trivial types it's better to explicitly use either the Containers:: ValueInit or Containers:: NoInit variants instead. - allocateAligned(Containers::
ValueInitT, std:: size_t) is equivalent to the default case, zero-initializing trivial types and calling the default constructor elsewhere. Useful when you want to make the choice appear explicit. - allocateAligned(Containers::
NoInitT, std:: size_t) does not initialize anything. Useful for trivial types when you'll be overwriting the contents anyway, for non-trivial types this is the dangerous option and you need to call the constructor on all elements manually using placement new, std:: uninitialized_copy() or similar — see the function docs for an example.
template<class T, std:: size_t alignment = alignof(T)>
static Containers:: Array<T> Death:: Memory:: allocateAligned(Containers:: DefaultInitT,
std:: size_t size)
Allocate aligned memory and default-initialize it.
Compared to allocateAligned(std::
Implemented via allocateAligned(Containers::
template<class T, std:: size_t alignment = alignof(T)>
static Containers:: Array<T> Death:: Memory:: allocateAligned(Containers:: ValueInitT,
std:: size_t size)
Allocate aligned memory and value-initialize it.
Same as allocateAligned(std::
template<class T, std:: size_t alignment = alignof(T)>
static Containers:: Array<T> Death:: Memory:: allocateAligned(Containers:: NoInitT,
std:: size_t size)
Allocate aligned memory and leave it uninitialized.
Compared to allocateAligned(std::