This commit is contained in:
IlushaShurupov 2023-07-16 18:28:24 +03:00
parent fabceb52d3
commit bc892da992
24 changed files with 116 additions and 110 deletions

View file

@ -3,8 +3,12 @@
#include <cstdlib>
static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleBase, nullptr };
tp::ModuleManifest tp::gModuleAllocators = ModuleManifest("Allocators", nullptr, nullptr, sModuleDependencies);
static void deinit(const tp::ModuleManifest* self) {
tp::HeapAllocGlobal::checkLeaks();
}
static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleUtils, nullptr };
tp::ModuleManifest tp::gModuleAllocators = ModuleManifest("Allocators", nullptr, deinit, sModuleDependencies);
void* operator new(size_t aSize) { return tp::HeapAllocGlobal::allocate(aSize); }

View file

@ -118,8 +118,15 @@ void HeapAllocGlobal::deallocate(void* aPtr) {
}
// 3) Check the wrap
ASSERT(!memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
ASSERT(!memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
if (memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL)) {
CallStackCapture::printSnapshot(head->mCallStack);
ASSERT(!"Allocated Block Wrap Corrupted!")
}
if (memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL)) {
CallStackCapture::printSnapshot(head->mCallStack);
ASSERT(!"Allocated Block Wrap Corrupted!")
}
// 4) clear data
#ifdef MEM_CLEAR_ON_ALLOC
@ -135,10 +142,12 @@ bool HeapAllocGlobal::checkLeaks() {
if (mNumAllocations) {
#ifdef MEM_STACK_TRACE
gCSCapture->logLeaks();
for (auto iter = mEntry; iter; iter = iter->mPrev) {
CallStackCapture::printSnapshot(iter->mCallStack);
}
#endif
DEBUG_BREAK("Destruction of not freed Allocator")
ASSERT(!"Destruction of not freed Allocator")
return true;
}
return false;

View file

@ -1,6 +1,6 @@
#pragma once
#include "Module.hpp"
#include "Utils.hpp"
#include "HeapAllocatorGlobal.hpp"
#include "HeapAllocator.hpp"
@ -12,6 +12,7 @@ namespace tp {
}
inline void* operator new(std::size_t aSize, void* aWhere) noexcept { return aWhere; }
inline void* operator new[](std::size_t aSize, void* aWhere) noexcept { return aWhere; }
void* operator new(std::size_t aSize);
void* operator new[](std::size_t aSize);