From 0c29b828c4330f2ef0b60303baac90a47f563a5e Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 20 Nov 2022 13:21:02 +0900 Subject: [PATCH] overload global new/delete to observe allocations --- main.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.cc b/main.cc index 417388c..fe491d2 100644 --- a/main.cc +++ b/main.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -614,3 +615,20 @@ int main(int, char**) { } return 0; } + + +void* operator new(size_t n) { + auto ptr = std::malloc(n); + if (!ptr) { + throw nf7::Exception {"allocation failure"}; + } + TracyAlloc(ptr, n); + return ptr; +} +void operator delete(void* ptr) noexcept { + TracyFree(ptr); + std::free(ptr); +} +void operator delete(void* ptr, size_t) noexcept { + operator delete(ptr); +}