From a453577c35db77b3c4894c77dc497d50c1b569b5 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Fri, 31 Jan 2014 22:07:10 -0800 Subject: [PATCH] Added aligned new/delete. --- include/bx/allocator.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index c110395..40ab2b0 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -22,8 +22,10 @@ # define BX_ALIGNED_ALLOC(_allocator, _size, _align) bx::alignedAlloc(_allocator, _size, _align, __FILE__, __LINE__) # define BX_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) bx::alignedRealloc(_allocator, _ptr, _size, _align, __FILE__, __LINE__) # define BX_ALIGNED_FREE(_allocator, _ptr) bx::alignedFree(_allocator, _ptr, __FILE__, __LINE__) -# define BX_NEW(_allocator, _type) new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type +# define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, __FILE__, __LINE__) +# define BX_ALIGNED_NEW(_allocator, _align, _type) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_DELETE(_allocator, _align, _ptr) bx::alignedDeleteObject(_allocator, _ptr) #else # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size) # define BX_REALLOC(_allocator, _ptr, _size) bx::realloc(_allocator, _ptr, _size) @@ -33,6 +35,8 @@ # define BX_ALIGNED_FREE(_allocator, _ptr) bx::alignedFree(_allocator, _ptr) # define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr) +# define BX_ALIGNED_NEW(_allocator, _align, _type) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type +# define BX_ALIGNED_DELETE(_allocator, _align, _ptr) bx::alignedDeleteObject(_allocator, _ptr) #endif // BX_CONFIG_DEBUG_ALLOC #ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT @@ -187,6 +191,16 @@ namespace bx } } + template + inline void alignedDeleteObject(AllocatorI* _allocator, ObjectT* _object, const char* _file = NULL, uint32_t _line = 0) + { + if (NULL != _object) + { + _object->~ObjectT(); + alignedFree(_allocator, _object, _file, _line); + } + } + #if BX_CONFIG_ALLOCATOR_CRT class CrtAllocator : public ReallocatorI, public AlignedReallocatorI {