Add linearSpaceFree() for retrieving the free space in the linear heap

This commit is contained in:
fincs 2014-11-03 20:20:33 +01:00
parent c7be1e415f
commit a77e8ae1cd
4 changed files with 15 additions and 0 deletions

View File

@ -4,3 +4,4 @@
void* linearAlloc(size_t size); void* linearAlloc(size_t size);
void* linearRealloc(void* mem, size_t size); void* linearRealloc(void* mem, size_t size);
void linearFree(void* mem); void linearFree(void* mem);
u32 linearSpaceFree(); // get free linear space in bytes

View File

@ -48,3 +48,8 @@ void linearFree(void* mem)
auto pChunk = (MemChunk*)((u8*)mem - 16); auto pChunk = (MemChunk*)((u8*)mem - 16);
sLinearPool.Deallocate(*pChunk); sLinearPool.Deallocate(*pChunk);
} }
u32 linearSpaceFree()
{
return sLinearPool.GetFreeSpace();
}

View File

@ -123,3 +123,11 @@ void MemPool::Dump(const char* title)
printf(" - %p (%u bytes)\n", b->base, b->size); printf(" - %p (%u bytes)\n", b->base, b->size);
} }
*/ */
u32 MemPool::GetFreeSpace()
{
u32 acc = 0;
for (auto b = first; b; b = b->next)
acc += b->size;
return acc;
}

View File

@ -85,4 +85,5 @@ struct MemPool
} }
//void Dump(const char* title); //void Dump(const char* title);
u32 GetFreeSpace();
}; };