35 #ifndef _BLAZE_UTIL_MEMORY_H_ 36 #define _BLAZE_UTIL_MEMORY_H_ 43 #if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32__) 79 inline byte_t* allocate_backend(
size_t size,
size_t alignment )
83 #if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) 84 raw = _aligned_malloc( size, alignment );
85 if( raw ==
nullptr ) {
86 #elif defined(__MINGW32__) 87 raw = __mingw_aligned_malloc( size, alignment );
88 if( raw ==
nullptr ) {
90 if( posix_memalign( &raw, alignment, size ) ) {
95 return reinterpret_cast<byte_t*
>( raw );
112 inline void deallocate_backend(
const void* address ) noexcept
114 #if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) 115 _aligned_free( const_cast<void*>( address ) );
116 #elif defined(__MINGW32__) 117 __mingw_aligned_free( const_cast<void*>( address ) );
119 free( const_cast<void*>( address ) );
154 template<
typename T >
159 if( alignment >= 8UL ) {
160 return reinterpret_cast<T*
>( allocate_backend( size*
sizeof(T), alignment ) );
162 else return ::new T[
size];
183 template<
typename T >
187 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
192 if( alignment >= 8UL )
194 byte_t*
const raw( allocate_backend( size*
sizeof(T)+headersize, alignment ) );
196 *
reinterpret_cast<size_t*
>( raw ) = size;
198 T*
const address( reinterpret_cast<T*>( raw + headersize ) );
203 ::
new (address+i) T();
208 deallocate_backend( raw );
214 else return ::new T[
size];
229 template<
typename T >
232 if( address ==
nullptr )
237 if( alignment >= 8UL ) {
238 deallocate_backend( address );
240 else ::delete[] address;
255 template<
typename T >
258 if( address ==
nullptr )
262 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
267 if( alignment >= 8UL )
269 const byte_t*
const raw =
reinterpret_cast<byte_t*
>( address ) - headersize;
271 const size_t size( *reinterpret_cast<const size_t*>( raw ) );
272 for(
size_t i=0UL; i<
size; ++i )
275 deallocate_backend( raw );
277 else ::delete[] address;
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
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
Header file for exception macros.
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:224
#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
EnableIf_< IsBuiltin< T >, T *> allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:155
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.
EnableIf_< IsBuiltin< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:230
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
Header file for the IsBuiltin type trait.
#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
Evaluation of the required alignment of the given data type.The AlignmentOf type trait template evalu...
Definition: AlignmentOf.h:219