Renamed internal helper functions from the Memory header.

This commit is contained in:
Hauke Heibel 2009-06-04 17:25:15 +02:00
parent 5f04f8eb6b
commit f26c691678

View File

@ -116,10 +116,10 @@ template<> inline void* ei_conditional_aligned_malloc<false>(size_t size)
return result; return result;
} }
/** \internal in-place allocate the elements of an array. /** \internal construct the elements of an array.
* The \a size parameter tells on how many objects to call the constructor of T. * The \a size parameter tells on how many objects to call the constructor of T.
*/ */
template<typename T> inline T* ei_alloc_elements_of_array(T *ptr, size_t size) template<typename T> inline T* ei_construct_elements_of_array(T *ptr, size_t size)
{ {
for (size_t i=0; i < size; ++i) ::new (ptr + i) T; for (size_t i=0; i < size; ++i) ::new (ptr + i) T;
return ptr; return ptr;
@ -132,13 +132,13 @@ template<typename T> inline T* ei_alloc_elements_of_array(T *ptr, size_t size)
template<typename T> inline T* ei_aligned_new(size_t size) template<typename T> inline T* ei_aligned_new(size_t size)
{ {
T *result = reinterpret_cast<T*>(ei_aligned_malloc(sizeof(T)*size)); T *result = reinterpret_cast<T*>(ei_aligned_malloc(sizeof(T)*size));
return ei_alloc_elements_of_array(result, size); return ei_construct_elements_of_array(result, size);
} }
template<typename T, bool Align> inline T* ei_conditional_aligned_new(size_t size) template<typename T, bool Align> inline T* ei_conditional_aligned_new(size_t size)
{ {
T *result = reinterpret_cast<T*>(ei_conditional_aligned_malloc<Align>(sizeof(T)*size)); T *result = reinterpret_cast<T*>(ei_conditional_aligned_malloc<Align>(sizeof(T)*size));
return ei_alloc_elements_of_array(result, size); return ei_construct_elements_of_array(result, size);
} }
/** \internal free memory allocated with ei_aligned_malloc /** \internal free memory allocated with ei_aligned_malloc
@ -172,10 +172,10 @@ template<> inline void ei_conditional_aligned_free<false>(void *ptr)
free(ptr); free(ptr);
} }
/** \internal delete the elements of an array. /** \internal destruct the elements of an array.
* The \a size parameters tells on how many objects to call the destructor of T. * The \a size parameters tells on how many objects to call the destructor of T.
*/ */
template<typename T> inline void ei_delete_elements_of_array(T *ptr, size_t size) template<typename T> inline void ei_destruct_elements_of_array(T *ptr, size_t size)
{ {
// always destruct an array starting from the end. // always destruct an array starting from the end.
while(size) ptr[--size].~T(); while(size) ptr[--size].~T();
@ -186,7 +186,7 @@ template<typename T> inline void ei_delete_elements_of_array(T *ptr, size_t size
*/ */
template<typename T> inline void ei_aligned_delete(T *ptr, size_t size) template<typename T> inline void ei_aligned_delete(T *ptr, size_t size)
{ {
ei_delete_elements_of_array<T>(ptr, size); ei_destruct_elements_of_array<T>(ptr, size);
ei_aligned_free(ptr); ei_aligned_free(ptr);
} }
@ -195,7 +195,7 @@ template<typename T> inline void ei_aligned_delete(T *ptr, size_t size)
*/ */
template<typename T, bool Align> inline void ei_conditional_aligned_delete(T *ptr, size_t size) template<typename T, bool Align> inline void ei_conditional_aligned_delete(T *ptr, size_t size)
{ {
ei_delete_elements_of_array<T>(ptr, size); ei_destruct_elements_of_array<T>(ptr, size);
ei_conditional_aligned_free<Align>(ptr); ei_conditional_aligned_free<Align>(ptr);
} }
@ -234,8 +234,8 @@ inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset)
#define ei_aligned_stack_free(PTR,SIZE) ei_aligned_free(PTR) #define ei_aligned_stack_free(PTR,SIZE) ei_aligned_free(PTR)
#endif #endif
#define ei_aligned_stack_new(TYPE,SIZE) ei_alloc_elements_of_array(reinterpret_cast<TYPE*>(ei_aligned_stack_alloc(sizeof(TYPE)*SIZE)), SIZE) #define ei_aligned_stack_new(TYPE,SIZE) ei_construct_elements_of_array(reinterpret_cast<TYPE*>(ei_aligned_stack_alloc(sizeof(TYPE)*SIZE)), SIZE)
#define ei_aligned_stack_delete(TYPE,PTR,SIZE) do {ei_delete_elements_of_array<TYPE>(PTR, SIZE); \ #define ei_aligned_stack_delete(TYPE,PTR,SIZE) do {ei_destruct_elements_of_array<TYPE>(PTR, SIZE); \
ei_aligned_stack_free(PTR,sizeof(TYPE)*SIZE);} while(0) ei_aligned_stack_free(PTR,sizeof(TYPE)*SIZE);} while(0)