Removing <new> header.

This commit is contained in:
Branimir Karadžić
2017-07-15 14:32:13 -07:00
parent 0a986b4ae7
commit ce96145218
4 changed files with 25 additions and 13 deletions

View File

@@ -8,8 +8,6 @@
#include "bx.h"
#include <new>
#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.

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()