35 #ifndef _BLAZE_UTIL_MEMORY_H_
36 #define _BLAZE_UTIL_MEMORY_H_
81 inline byte* allocate_backend(
size_t size,
size_t alignment )
86 raw = _aligned_malloc( size, alignment );
89 if( posix_memalign( &raw, alignment, size ) ) {
94 return reinterpret_cast<byte*
>( raw );
111 inline void deallocate_backend(
const void* address )
113 #if defined(_MSC_VER)
114 _aligned_free( const_cast<void*>( address ) );
116 free( const_cast<void*>( address ) );
151 template<
typename T >
156 if( alignment >= 8UL ) {
157 return reinterpret_cast<T*
>( allocate_backend( size*
sizeof(T), alignment ) );
159 else return ::new T[
size];
180 template<
typename T >
184 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
189 if( alignment >= 8UL )
191 byte*
const raw( allocate_backend( size*
sizeof(T)+headersize, alignment ) );
193 *
reinterpret_cast<size_t*
>( raw ) = size;
195 T*
const address( reinterpret_cast<T*>( raw + headersize ) );
200 ::
new (address+i) T();
205 deallocate_backend( raw );
211 else return ::new T[
size];
226 template<
typename T >
229 if( address == NULL )
234 if( alignment >= 8UL ) {
235 deallocate_backend( address );
237 else delete[] address;
252 template<
typename T >
255 if( address == NULL )
259 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
264 if( alignment >= 8UL )
266 const byte*
const raw =
reinterpret_cast<byte*
>( address ) - headersize;
268 const size_t size( *reinterpret_cast<const size_t*>( raw ) );
269 for(
size_t i=0UL; i<
size; ++i )
272 deallocate_backend( raw );
274 else delete[] address;
Header file for the AlignmentOf type trait.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
#define BLAZE_THROW_BAD_ALLOC
Macro for the emission of a std::bad_alloc exceptionThis macro encapsulates the default way of Blaze ...
Definition: Exception.h:139
EnableIf< IsBuiltin< T >, T * >::Type allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:152
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
EnableIf< IsBuiltin< T > >::Type deallocate(T *address)
Deallocation of memory for built-in data types.
Definition: Memory.h:227
Header file for the EnableIf class template.
Header file for the byte type.
Header file for run time assertion macros.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
Header file for the IsBuiltin type trait.
unsigned char byte
Byte data type of the Blaze library.The byte data type is guaranteed to be an integral data type of s...
Definition: Byte.h:61
Header file for exception macros.
#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:77
Header file for a safe C++ NULL pointer implementation.