35#ifndef _BLAZE_UTIL_MEMORY_H_
36#define _BLAZE_UTIL_MEMORY_H_
56#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM || BLAZE_MINGW32_PLATFORM || BLAZE_MINGW64_PLATFORM
86#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM || BLAZE_MINGW64_PLATFORM
87 raw = _aligned_malloc(
size, alignment );
88 if( raw ==
nullptr ) {
89#elif BLAZE_MINGW32_PLATFORM
90 raw = __mingw_aligned_malloc(
size, alignment );
91 if( raw ==
nullptr ) {
93 alignment = ( alignment <
sizeof(
void*) ?
sizeof(
void*) : alignment );
94 if( posix_memalign( &raw, alignment,
size ) ) {
99 return reinterpret_cast<byte_t*
>( raw );
117#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM || BLAZE_MINGW64_PLATFORM
118 _aligned_free(
const_cast<void*
>( address ) );
119#elif BLAZE_MINGW32_PLATFORM
120 __mingw_aligned_free(
const_cast<void*
>( address ) );
122 free(
const_cast<void*
>( address ) );
157 , EnableIf_t< IsBuiltin_v<T> >* =
nullptr >
160 constexpr size_t alignment( AlignmentOf_v<T> );
184 , DisableIf_t< IsBuiltin_v<T> >* =
nullptr >
187 constexpr size_t alignment ( AlignmentOf_v<T> );
188 constexpr size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
195 *
reinterpret_cast<size_t*
>( raw ) =
size;
197 T*
const address(
reinterpret_cast<T*
>( raw + headersize ) );
201 for( ; i<
size; ++i ) {
206 for( ; i>0UL; --i ) {
229 , EnableIf_t< IsBuiltin_v<T> >* =
nullptr >
232 if( address ==
nullptr )
251 , DisableIf_t< IsBuiltin_v<T> >* =
nullptr >
254 if( address ==
nullptr )
257 constexpr size_t alignment ( AlignmentOf_v<T> );
258 constexpr size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
263 const byte_t*
const raw =
reinterpret_cast<byte_t*
>( address ) - headersize;
264 const size_t size( *
reinterpret_cast<const size_t*
>( raw ) );
Header file for the AlignmentOf type trait.
Header file for run time assertion macros.
Header file for the generic construct_at algorithm.
Header file for the generic destroy_at algorithm.
Header file for the generic destroy algorithm.
Header file for the EnableIf class template.
Header file for the IsBuiltin type trait.
void construct_at(T *p, Args &&... args)
Constructs the object at the given address.
Definition: ConstructAt.h:58
void destroy_n(ForwardIt first, size_t n)
Destroys the given range of objects .
Definition: Destroy.h:87
void destroy_at(T *p) noexcept
Destroys the object at the given address.
Definition: DestroyAt.h:57
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
void deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:230
void alignedDeallocate(const void *address) noexcept
Deallocation of aligned memory.
Definition: Memory.h:115
byte_t * alignedAllocate(size_t size, size_t alignment)
Aligned array allocation.
Definition: Memory.h:82
unsigned char byte_t
Byte data type of the Blaze library.
Definition: Types.h:79
T * allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:158
#define BLAZE_THROW_BAD_ALLOC
Macro for the emission of a std::bad_alloc exception.
Definition: Exception.h:139
Header file for exception macros.
Header file for basic type definitions.