35 #ifndef _BLAZE_UTIL_MEMORY_H_ 36 #define _BLAZE_UTIL_MEMORY_H_ 43 #if BLAZE_WIN64_PLATFORM || BLAZE_MINGW64_PLATFORM || BLAZE_MINGW32_PLATFORM 79 inline byte_t* allocate_backend(
size_t size,
size_t alignment )
83 #if BLAZE_WIN64_PLATFORM || BLAZE_MINGW64_PLATFORM 84 raw = _aligned_malloc(
size, alignment );
85 if( raw ==
nullptr ) {
86 #elif BLAZE_MINGW32_PLATFORM 87 raw = __mingw_aligned_malloc(
size, alignment );
88 if( raw ==
nullptr ) {
90 alignment = ( alignment <
sizeof(
void*) ?
sizeof(
void*) : alignment );
91 if( posix_memalign( &raw, alignment,
size ) ) {
96 return reinterpret_cast<byte_t*
>( raw );
113 inline void deallocate_backend(
const void* address ) noexcept
115 #if BLAZE_WIN64_PLATFORM || BLAZE_MINGW64_PLATFORM 116 _aligned_free( const_cast<void*>( address ) );
117 #elif BLAZE_MINGW32_PLATFORM 118 __mingw_aligned_free( const_cast<void*>( address ) );
120 free( const_cast<void*>( address ) );
155 template<
typename T >
158 constexpr
size_t alignment( AlignmentOf_v<T> );
160 return reinterpret_cast<T*
>( allocate_backend(
size*
sizeof(T), alignment ) );
181 template<
typename T >
184 constexpr
size_t alignment ( AlignmentOf_v<T> );
185 constexpr
size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
190 byte_t*
const raw( allocate_backend(
size*
sizeof(T)+headersize, alignment ) );
192 *
reinterpret_cast<size_t*
>( raw ) =
size;
194 T*
const address( reinterpret_cast<T*>( raw + headersize ) );
199 ::
new (address+i) T();
204 deallocate_backend( raw );
223 template<
typename T >
226 if( address ==
nullptr )
229 deallocate_backend( address );
244 template<
typename T >
247 if( address ==
nullptr )
250 constexpr
size_t alignment ( AlignmentOf_v<T> );
251 constexpr
size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
256 const byte_t*
const raw =
reinterpret_cast<byte_t*
>( address ) - headersize;
258 const size_t size( *reinterpret_cast<const size_t*>( raw ) );
259 for(
size_t i=0UL; i<
size; ++i )
262 deallocate_backend( raw );
Header file for the AlignmentOf type trait.
Header file for basic type definitions.
unsigned char byte_t
Byte data type of the Blaze library.The byte data type is guaranteed to be an integral data type of s...
Definition: Types.h:79
Header file for exception macros.
#define BLAZE_THROW_BAD_ALLOC
Macro for the emission of a std::bad_alloc exception.This macro encapsulates the default way of Blaze...
Definition: Exception.h:139
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the EnableIf class template.
Header file for run time assertion macros.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
EnableIf_t< IsBuiltin_v< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:224
Header file for the IsBuiltin type trait.
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
EnableIf_t< IsBuiltin_v< T >, T *> allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:156
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101