From ce96145218146420d7a7d03287430393432e13b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 15 Jul 2017 14:32:13 -0700 Subject: [PATCH] Removing header. --- include/bx/allocator.h | 19 +++++++++---------- include/bx/inline/allocator.inl | 9 +++++++++ include/bx/inline/handlealloc.inl | 2 +- src/crtimpl.cpp | 8 ++++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index 77646a5..67aa7ea 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -8,8 +8,6 @@ #include "bx.h" -#include - #if BX_CONFIG_ALLOCATOR_DEBUG # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size, 0, __FILE__, __LINE__) # define BX_REALLOC(_allocator, _ptr, _size) bx::realloc(_allocator, _ptr, _size, 0, __FILE__, __LINE__) @@ -17,9 +15,7 @@ # define BX_ALIGNED_ALLOC(_allocator, _size, _align) bx::alloc(_allocator, _size, _align, __FILE__, __LINE__) # define BX_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) bx::realloc(_allocator, _ptr, _size, _align, __FILE__, __LINE__) # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align, __FILE__, __LINE__) -# define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, 0, __FILE__, __LINE__) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::deleteObject(_allocator, _ptr, _align, __FILE__, __LINE__) #else # define BX_ALLOC(_allocator, _size) bx::alloc(_allocator, _size, 0) @@ -28,15 +24,18 @@ # define BX_ALIGNED_ALLOC(_allocator, _size, _align) bx::alloc(_allocator, _size, _align) # define BX_ALIGNED_REALLOC(_allocator, _ptr, _size, _align) bx::realloc(_allocator, _ptr, _size, _align) # define BX_ALIGNED_FREE(_allocator, _ptr, _align) bx::free(_allocator, _ptr, _align) -# define BX_NEW(_allocator, _type) ::new(BX_ALLOC(_allocator, sizeof(_type) ) ) _type # define BX_DELETE(_allocator, _ptr) bx::deleteObject(_allocator, _ptr, 0) -# define BX_ALIGNED_NEW(_allocator, _type, _align) ::new(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align) ) _type # define BX_ALIGNED_DELETE(_allocator, _ptr, _align) bx::deleteObject(_allocator, _ptr, _align) #endif // BX_CONFIG_DEBUG_ALLOC -#ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT -# define BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 8 -#endif // BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT +#define BX_NEW(_allocator, _type) BX_PLACEMENT_NEW(BX_ALLOC(_allocator, sizeof(_type) ), _type) +#define BX_ALIGNED_NEW(_allocator, _type, _align) BX_PLACEMENT_NEW(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align), _type) +#define BX_PLACEMENT_NEW(_ptr, _type) ::new(bx::PlacementNewTag(), _ptr) _type + +namespace bx { struct PlacementNewTag {}; } + +void* operator new(size_t, bx::PlacementNewTag, void* _ptr); +void operator delete(void*, bx::PlacementNewTag, void*) throw(); namespace bx { @@ -64,7 +63,7 @@ namespace bx void* alignPtr( void* _ptr , size_t _extra - , size_t _align = BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT + , size_t _align = 0 ); /// Allocate memory. diff --git a/include/bx/inline/allocator.inl b/include/bx/inline/allocator.inl index 8a4898d..7362d3f 100644 --- a/include/bx/inline/allocator.inl +++ b/include/bx/inline/allocator.inl @@ -7,6 +7,15 @@ # error "Must be included from bx/allocator.h" #endif // BX_ALLOCATOR_H_HEADER_GUARD +inline void* operator new(size_t, bx::PlacementNewTag, void* _ptr) +{ + return _ptr; +} + +inline void operator delete(void*, bx::PlacementNewTag, void*) throw() +{ +} + namespace bx { inline AllocatorI::~AllocatorI() diff --git a/include/bx/inline/handlealloc.inl b/include/bx/inline/handlealloc.inl index dd6a0e1..3ca3d41 100644 --- a/include/bx/inline/handlealloc.inl +++ b/include/bx/inline/handlealloc.inl @@ -104,7 +104,7 @@ namespace bx inline HandleAlloc* createHandleAlloc(AllocatorI* _allocator, uint16_t _maxHandles) { uint8_t* ptr = (uint8_t*)BX_ALLOC(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) ); - return ::new (ptr) HandleAlloc(_maxHandles); + return BX_PLACEMENT_NEW(ptr, HandleAlloc)(_maxHandles); } inline void destroyHandleAlloc(AllocatorI* _allocator, HandleAlloc* _handleAlloc) diff --git a/src/crtimpl.cpp b/src/crtimpl.cpp index c5f3f93..742d87f 100644 --- a/src/crtimpl.cpp +++ b/src/crtimpl.cpp @@ -24,6 +24,10 @@ ) #endif // BX_CONFIG_CRT_PROCESS +#ifndef BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT +# define BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT 8 +#endif // BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT + namespace bx { DefaultAllocator::DefaultAllocator() @@ -332,7 +336,7 @@ namespace bx FileReader::FileReader() { BX_STATIC_ASSERT(sizeof(FileReaderImpl) <= sizeof(m_internal) ); - new(m_internal) FileReaderImpl(NULL); + BX_PLACEMENT_NEW(m_internal, FileReaderImpl)(NULL); } FileReader::~FileReader() @@ -368,7 +372,7 @@ namespace bx FileWriter::FileWriter() { BX_STATIC_ASSERT(sizeof(FileWriterImpl) <= sizeof(m_internal) ); - new(m_internal) FileWriterImpl(NULL); + BX_PLACEMENT_NEW(m_internal, FileWriterImpl)(NULL); } FileWriter::~FileWriter()