| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
JPH_NAMESPACE_BEGIN |
| 8 |
|
| 9 |
#ifndef JPH_DISABLE_CUSTOM_ALLOCATOR |
| 10 |
|
| 11 |
|
| 12 |
using AllocateFunction = void *(*)(size_t inSize); |
| 13 |
using ReallocateFunction = void *(*)(void *inBlock, size_t inOldSize, size_t inNewSize); |
| 14 |
using FreeFunction = void (*)(void *inBlock); |
| 15 |
|
| 16 |
|
| 17 |
using AlignedAllocateFunction = void *(*)(size_t inSize, size_t inAlignment); |
| 18 |
using AlignedFreeFunction = void (*)(void *inBlock); |
| 19 |
|
| 20 |
|
| 21 |
JPH_EXPORT extern AllocateFunction Allocate; |
| 22 |
JPH_EXPORT extern ReallocateFunction Reallocate; |
| 23 |
JPH_EXPORT extern FreeFunction Free; |
| 24 |
JPH_EXPORT extern AlignedAllocateFunction AlignedAllocate; |
| 25 |
JPH_EXPORT extern AlignedFreeFunction AlignedFree; |
| 26 |
|
| 27 |
|
| 28 |
JPH_EXPORT void RegisterDefaultAllocator(); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#if defined(JPH_COMPILER_MINGW) && JPH_CPU_ADDRESS_BITS == 32 |
| 35 |
#define JPH_INTERNAL_DEFAULT_ALLOCATE(size) JPH::AlignedAllocate(size, 16) |
| 36 |
#define JPH_INTERNAL_DEFAULT_FREE(pointer) JPH::AlignedFree(pointer) |
| 37 |
#else |
| 38 |
#define JPH_INTERNAL_DEFAULT_ALLOCATE(size) JPH::Allocate(size) |
| 39 |
#define JPH_INTERNAL_DEFAULT_FREE(pointer) JPH::Free(pointer) |
| 40 |
#endif |
| 41 |
|
| 42 |
|
| 43 |
#define JPH_OVERRIDE_NEW_DELETE \ |
| 44 |
JPH_INLINE void *operator new (size_t inCount) { return JPH_INTERNAL_DEFAULT_ALLOCATE(inCount); } \ |
| 45 |
JPH_INLINE void operator delete (void *inPointer) noexcept { JPH_INTERNAL_DEFAULT_FREE(inPointer); } \ |
| 46 |
JPH_INLINE void *operator new[] (size_t inCount) { return JPH_INTERNAL_DEFAULT_ALLOCATE(inCount); } \ |
| 47 |
JPH_INLINE void operator delete[] (void *inPointer) noexcept { JPH_INTERNAL_DEFAULT_FREE(inPointer); } \ |
| 48 |
JPH_INLINE void *operator new (size_t inCount, std::align_val_t inAlignment) { return JPH::AlignedAllocate(inCount, static_cast<size_t>(inAlignment)); } \ |
| 49 |
JPH_INLINE void operator delete (void *inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept { JPH::AlignedFree(inPointer); } \ |
| 50 |
JPH_INLINE void *operator new[] (size_t inCount, std::align_val_t inAlignment) { return JPH::AlignedAllocate(inCount, static_cast<size_t>(inAlignment)); } \ |
| 51 |
JPH_INLINE void operator delete[] (void *inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept { JPH::AlignedFree(inPointer); } \ |
| 52 |
JPH_INLINE void *operator new ([[maybe_unused]] size_t inCount, void *inPointer) noexcept { return inPointer; } \ |
| 53 |
JPH_INLINE void operator delete ([[maybe_unused]] void *inPointer, [[maybe_unused]] void *inPlace) noexcept { } \ |
| 54 |
JPH_INLINE void *operator new[] ([[maybe_unused]] size_t inCount, void *inPointer) noexcept { return inPointer; } \ |
| 55 |
JPH_INLINE void operator delete[] ([[maybe_unused]] void *inPointer, [[maybe_unused]] void *inPlace) noexcept { } |
| 56 |
|
| 57 |
#else |
| 58 |
|
| 59 |
|
| 60 |
JPH_EXPORT void *Allocate(size_t inSize); |
| 61 |
JPH_EXPORT void *Reallocate(void *inBlock, size_t inOldSize, size_t inNewSize); |
| 62 |
JPH_EXPORT void Free(void *inBlock); |
| 63 |
JPH_EXPORT void *AlignedAllocate(size_t inSize, size_t inAlignment); |
| 64 |
JPH_EXPORT void AlignedFree(void *inBlock); |
| 65 |
|
| 66 |
|
| 67 |
inline void RegisterDefaultAllocator() { } |
| 68 |
|
| 69 |
|
| 70 |
#define JPH_OVERRIDE_NEW_DELETE |
| 71 |
|
| 72 |
#endif |
| 73 |
|
| 74 |
JPH_NAMESPACE_END |