00001 #include "HeapManager.h" 00002 00009 00018 size_t HeapFreeSpace(HEAP_BLOCK *pHeap) 00019 { 00020 //---------------------------------- 00021 // walk the free list and calculate 00022 // the number of free bytes 00023 // 00024 // A return value of 0 could mean 00025 // that malloc just hasn't been called 00026 // yet. 00027 //---------------------------------- 00028 struct __freelist *pHF; 00029 size_t Free = 0; 00030 00031 pHF = pHeap->__flp; 00032 00033 while(pHF) 00034 { 00035 Free += pHF->sz; 00036 pHF = pHF->nx; 00037 } 00038 if (pHeap->BrkVal == 0) pHeap->BrkVal = pHeap->Start; 00039 Free += (size_t)(pHeap->End - pHeap->BrkVal); 00040 return Free; 00041 } 00042