35 #ifndef _BLAZE_UTIL_MEMORY_H_
36 #define _BLAZE_UTIL_MEMORY_H_
79 inline byte_t* allocate_backend(
size_t size,
size_t alignment )
84 raw = _aligned_malloc( size, alignment );
85 if( raw ==
nullptr ) {
87 if( posix_memalign( &raw, alignment, size ) ) {
92 return reinterpret_cast<byte_t*
>( raw );
109 inline void deallocate_backend(
const void* address ) noexcept
111 #if defined(_MSC_VER)
112 _aligned_free( const_cast<void*>( address ) );
114 free( const_cast<void*>( address ) );
149 template<
typename T >
154 if( alignment >= 8UL ) {
155 return reinterpret_cast<T*
>( allocate_backend( size*
sizeof(T), alignment ) );
157 else return ::new T[
size];
178 template<
typename T >
182 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
187 if( alignment >= 8UL )
189 byte_t*
const raw( allocate_backend( size*
sizeof(T)+headersize, alignment ) );
191 *
reinterpret_cast<size_t*
>( raw ) = size;
193 T*
const address( reinterpret_cast<T*>( raw + headersize ) );
198 ::
new (address+i) T();
203 deallocate_backend( raw );
209 else return ::new T[
size];
224 template<
typename T >
227 if( address ==
nullptr )
232 if( alignment >= 8UL ) {
233 deallocate_backend( address );
235 else delete[] address;
250 template<
typename T >
253 if( address ==
nullptr )
257 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
262 if( alignment >= 8UL )
264 const byte_t*
const raw =
reinterpret_cast<byte_t*
>( address ) - headersize;
266 const size_t size( *reinterpret_cast<const size_t*>( raw ) );
267 for(
size_t i=0UL; i<
size; ++i )
270 deallocate_backend( raw );
272 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:258
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:223
#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:150
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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:225
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
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:207