overload global new/delete to observe allocations

This commit is contained in:
falsycat 2022-11-20 13:21:02 +09:00
parent 74207a0b63
commit 0c29b828c4

18
main.cc
View File

@ -2,6 +2,7 @@
#include <cassert>
#include <chrono>
#include <condition_variable>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <mutex>
@ -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);
}