[+] Debug heap API: void Heap::WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg)
This commit is contained in:
parent
bf398be94e
commit
2a5fad9d0c
@ -16,6 +16,7 @@ namespace Aurora::Memory
|
||||
virtual AuSPtr<Heap> AllocateDivision(AuUInt32 heap, AuUInt32 alignment = 32) = 0;
|
||||
virtual Types::size_t GetChunkSize(const void *pHead) = 0;
|
||||
virtual HeapStats &GetStats() = 0;
|
||||
virtual void WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg) = 0;
|
||||
|
||||
template<typename T = void *>
|
||||
T ZAlloc(Types::size_t length)
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "DefaultHeap.hpp"
|
||||
#include "Heap.hpp"
|
||||
#include <Source/Debug/MemoryCrunch.hpp>
|
||||
#include <mimalloc.h>
|
||||
|
||||
namespace Aurora::Memory
|
||||
{
|
||||
@ -80,6 +81,26 @@ namespace Aurora::Memory
|
||||
return this;
|
||||
}
|
||||
|
||||
struct WalkInstance
|
||||
{
|
||||
bool(*fCallback)(void *, void *);
|
||||
void *pSecondArg;
|
||||
};
|
||||
|
||||
static bool mi_block_visit_funHandler(const mi_heap_t *heap, const mi_heap_area_t *area, void *block, size_t block_size, void *arg)
|
||||
{
|
||||
auto pWalkInstance = (WalkInstance *)arg;
|
||||
return pWalkInstance->fCallback(block, pWalkInstance->pSecondArg);
|
||||
}
|
||||
|
||||
void WalkHeap(bool(*fCallback)(void *, void*), void *pSecondArg) override
|
||||
{
|
||||
WalkInstance inst;
|
||||
inst.fCallback = fCallback;
|
||||
inst.pSecondArg = pSecondArg;
|
||||
mi_heap_visit_blocks(nullptr, true, &mi_block_visit_funHandler, &inst);
|
||||
}
|
||||
|
||||
void UpdateStats() override
|
||||
{
|
||||
auto other = AuDebug::gReserveHeap->GetStats();
|
||||
|
@ -97,6 +97,8 @@ namespace Aurora::Memory
|
||||
|
||||
void UpdateStats() override;
|
||||
|
||||
void WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg) override;
|
||||
|
||||
private:
|
||||
O1HeapInstance *heap_ {};
|
||||
int count_ {};
|
||||
@ -356,6 +358,11 @@ namespace Aurora::Memory
|
||||
this->stats.uBytesPeakCounter = pDiag.peak_allocated;
|
||||
}
|
||||
|
||||
void InternalHeap::WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg)
|
||||
{
|
||||
o1heapTraverseHeap(this->heap_, fCallback, pSecondArg);
|
||||
}
|
||||
|
||||
AuSPtr<Heap> InternalHeap::GetSelfReference()
|
||||
{
|
||||
try
|
||||
|
@ -275,6 +275,11 @@ namespace Aurora::Memory
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProxyHeap::WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg)
|
||||
{
|
||||
this->pHeap->WalkHeap(fCallback, pSecondArg);
|
||||
}
|
||||
|
||||
AUKN_SYM Heap *HeapProxyNew(const AuSPtr<Heap> &pHeap)
|
||||
{
|
||||
if (!pHeap)
|
||||
|
@ -37,5 +37,6 @@ namespace Aurora::Memory
|
||||
void *_FRealloc(void *buffer, Types::size_t length, Types::size_t align) override;
|
||||
void *_FRealloc(void *buffer, Types::size_t length) override;
|
||||
void _Free(void *buffer) override;
|
||||
void WalkHeap(bool(*fCallback)(void *, void *), void *pSecondArg) override;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user