Add a function to get the total free space left on the heaps

This commit is contained in:
Maschell 2020-05-30 21:49:29 +02:00
parent 3a0abb940f
commit 5ac51ef3ce
3 changed files with 18 additions and 0 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -165,6 +165,8 @@ public:
static void setupMemoryMapping();
static uint32_t GetFreeSpace();
static void CreateHeaps();
static void DestroyHeaps();