|
| 1 | + |
| 2 | +// these symbols need to live in the global namespace. |
| 3 | + |
| 4 | +#include <memory> |
| 5 | +#include <Allocator.hpp> |
| 6 | + |
| 7 | +namespace TiltedPhoques |
| 8 | +{ |
| 9 | + inline void* TPAlloc(const size_t acSize) |
| 10 | + { |
| 11 | + return TiltedPhoques::Allocator::Get()->Allocate(acSize); |
| 12 | + } |
| 13 | + |
| 14 | + inline void TPFree(void* apBlock) |
| 15 | + { |
| 16 | + TiltedPhoques::Allocator::Get()->Free(apBlock); |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// NOTE(Force): this replaces the global c++ operators, note that this is transitive, e.g. |
| 21 | +// it replaces the symbols for all projects. |
| 22 | +#ifdef TPCORE_CXX_ALLOCATOR_OVERRIDE |
| 23 | + |
| 24 | +void* operator new(size_t size) |
| 25 | +{ |
| 26 | + return TiltedPhoques::TPAlloc(size); |
| 27 | +} |
| 28 | + |
| 29 | +void operator delete(void* p) noexcept |
| 30 | +{ |
| 31 | + TiltedPhoques::TPFree(p); |
| 32 | +} |
| 33 | + |
| 34 | +void* operator new[](size_t size) |
| 35 | +{ |
| 36 | + return TiltedPhoques::TPAlloc(size); |
| 37 | +} |
| 38 | + |
| 39 | +void operator delete[](void* p) noexcept |
| 40 | +{ |
| 41 | + TiltedPhoques::TPFree(p); |
| 42 | +} |
| 43 | + |
| 44 | +void* operator new(size_t size, const std::nothrow_t&) noexcept |
| 45 | +{ |
| 46 | + return TiltedPhoques::TPAlloc(size); |
| 47 | +} |
| 48 | + |
| 49 | +void* operator new[](size_t size, const std::nothrow_t&) noexcept |
| 50 | +{ |
| 51 | + return TiltedPhoques::TPAlloc(size); |
| 52 | +} |
| 53 | + |
| 54 | +void operator delete(void* p, const std::nothrow_t&) noexcept |
| 55 | +{ |
| 56 | + TiltedPhoques::TPFree(p); |
| 57 | +} |
| 58 | + |
| 59 | +void operator delete[](void* p, const std::nothrow_t&) noexcept |
| 60 | +{ |
| 61 | + TiltedPhoques::TPFree(p); |
| 62 | +} |
| 63 | + |
| 64 | +void operator delete(void* p, size_t) noexcept |
| 65 | +{ |
| 66 | + TiltedPhoques::TPFree(p); |
| 67 | +} |
| 68 | + |
| 69 | +void operator delete[](void* p, size_t) noexcept |
| 70 | +{ |
| 71 | + TiltedPhoques::TPFree(p); |
| 72 | +} |
| 73 | + |
| 74 | +#endif |
0 commit comments