Skip to content

Commit be8b314

Browse files
committed
feat: optional allocator override
1 parent 900ac3e commit be8b314

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

MakeVSLatestProjects.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
3+
xmake project -k vsxmake2022
4+
timeout /t 3 /nobreak

xmake.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ if is_mode("release") then
1313
set_optimize("fastest")
1414
end
1515

16+
option("cxx_allocator_override")
17+
add_defines("TPCORE_CXX_ALLOCATOR_OVERRIDE")
18+
1619
target("TiltedCore")
1720
set_kind("static")
1821
add_files("Code/core/src/*.cpp")

0 commit comments

Comments
 (0)