Skip to content

Commit

Permalink
feat: optional allocator override
Browse files Browse the repository at this point in the history
  • Loading branch information
Force67 committed Mar 8, 2022
1 parent 900ac3e commit be8b314
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Code/core/include/AllocatorSymbolOverride.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

// these symbols need to live in the global namespace.

#include <memory>
#include <Allocator.hpp>

namespace TiltedPhoques
{
inline void* TPAlloc(const size_t acSize)
{
return TiltedPhoques::Allocator::Get()->Allocate(acSize);
}

inline void TPFree(void* apBlock)
{
TiltedPhoques::Allocator::Get()->Free(apBlock);
}
}

// NOTE(Force): this replaces the global c++ operators, note that this is transitive, e.g.
// it replaces the symbols for all projects.
#ifdef TPCORE_CXX_ALLOCATOR_OVERRIDE

void* operator new(size_t size)
{
return TiltedPhoques::TPAlloc(size);
}

void operator delete(void* p) noexcept
{
TiltedPhoques::TPFree(p);
}

void* operator new[](size_t size)
{
return TiltedPhoques::TPAlloc(size);
}

void operator delete[](void* p) noexcept
{
TiltedPhoques::TPFree(p);
}

void* operator new(size_t size, const std::nothrow_t&) noexcept
{
return TiltedPhoques::TPAlloc(size);
}

void* operator new[](size_t size, const std::nothrow_t&) noexcept
{
return TiltedPhoques::TPAlloc(size);
}

void operator delete(void* p, const std::nothrow_t&) noexcept
{
TiltedPhoques::TPFree(p);
}

void operator delete[](void* p, const std::nothrow_t&) noexcept
{
TiltedPhoques::TPFree(p);
}

void operator delete(void* p, size_t) noexcept
{
TiltedPhoques::TPFree(p);
}

void operator delete[](void* p, size_t) noexcept
{
TiltedPhoques::TPFree(p);
}

#endif
4 changes: 4 additions & 0 deletions MakeVSLatestProjects.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off

xmake project -k vsxmake2022
timeout /t 3 /nobreak
3 changes: 3 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if is_mode("release") then
set_optimize("fastest")
end

option("cxx_allocator_override")
add_defines("TPCORE_CXX_ALLOCATOR_OVERRIDE")

target("TiltedCore")
set_kind("static")
add_files("Code/core/src/*.cpp")
Expand Down

0 comments on commit be8b314

Please sign in to comment.