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 ) )
91 throw std::bad_alloc();
93 return reinterpret_cast<byte*
>( raw );
110 inline void deallocate_backend(
const void* address )
112 #if defined(_MSC_VER)
113 _aligned_free( const_cast<void*>( address ) );
115 free( const_cast<void*>( address ) );
150 template<
typename T >
155 if( alignment >= 8UL ) {
156 return reinterpret_cast<T*
>( allocate_backend( size*
sizeof(T), alignment ) );
158 else return ::new T[
size];
179 template<
typename T >
183 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
188 if( alignment >= 8UL )
190 byte*
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 );
210 else return ::new T[
size];
225 template<
typename T >
228 if( address == NULL )
233 if( alignment >= 8UL ) {
234 deallocate_backend( address );
236 else delete[] address;
251 template<
typename T >
254 if( address == NULL )
258 const size_t headersize( (
sizeof(
size_t) < alignment ) ? ( alignment ) : (
sizeof(
size_t ) ) );
263 if( alignment >= 8UL )
265 const byte*
const raw =
reinterpret_cast<byte*
>( address ) - headersize;
267 const size_t size( *reinterpret_cast<const size_t*>( raw ) );
268 for(
size_t i=0UL; i<
size; ++i )
271 deallocate_backend( raw );
273 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:264
EnableIf< IsBuiltin< T >, T * >::Type allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:151
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:226
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
#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.