From 5ac51ef3ce73d82d3315e9526f6d6e52253a06b5 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 30 May 2020 21:49:29 +0200 Subject: [PATCH] Add a function to get the total free space left on the heaps --- source/main.cpp | 3 +++ source/memory_mapping.cpp | 13 +++++++++++++ source/memory_mapping.h | 2 ++ 3 files changed, 18 insertions(+) diff --git a/source/main.cpp b/source/main.cpp index 0ef8f6e..50fc926 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -20,11 +20,14 @@ WUMS_INITIALIZE(){ MemoryMapping::setupMemoryMapping(); MemoryMapping::CreateHeaps(); + DEBUG_FUNCTION_LINE("total free space %d KiB", MemoryMapping::GetFreeSpace()/1024); } int main(int argc, char **argv) { + WHBLogUdpInit(); MemoryMapping::DestroyHeaps(); MemoryMapping::CreateHeaps(); + DEBUG_FUNCTION_LINE("total free space %d KiB", MemoryMapping::GetFreeSpace()/1024); return 0; } diff --git a/source/memory_mapping.cpp b/source/memory_mapping.cpp index 2442742..bbd6113 100644 --- a/source/memory_mapping.cpp +++ b/source/memory_mapping.cpp @@ -389,6 +389,19 @@ void MemoryMapping::free(void* ptr){ } } +uint32_t MemoryMapping::GetFreeSpace() { + uint32_t res = 0; + for(int32_t i = 0; /* waiting for a break */; i++) { + if(mem_mapping[i].physical_addresses == NULL) { + break; + } + uint32_t curRes = MEMGetTotalFreeSizeForExpHeap((MEMHeapHandle) mem_mapping[i].effective_start_address); + DEBUG_FUNCTION_LINE("heap at %08X MEMGetTotalFreeSizeForExpHeap: %d KiB",mem_mapping[i].effective_start_address, curRes/1024 ); + res+=curRes; + } + return res; +} + void MemoryMapping::CreateHeaps() { for (int32_t i = 0; /* waiting for a break */; i++) { if (mem_mapping[i].physical_addresses == NULL) { diff --git a/source/memory_mapping.h b/source/memory_mapping.h index deb7890..a176200 100644 --- a/source/memory_mapping.h +++ b/source/memory_mapping.h @@ -165,6 +165,8 @@ public: static void setupMemoryMapping(); + static uint32_t GetFreeSpace(); + static void CreateHeaps(); static void DestroyHeaps();