RTDECL(size_t) RTHeapOffsetSize(RTHEAPOFFSET hHeap, void *pv) { PRTHEAPOFFSETINTERNAL pHeapInt; PRTHEAPOFFSETBLOCK pBlock; size_t cbBlock; /* * Validate input. */ if (!pv) return 0; AssertPtrReturn(pv, 0); AssertReturn(RT_ALIGN_P(pv, RTHEAPOFFSET_ALIGNMENT) == pv, 0); /* * Get the block and heap. If in strict mode, validate these. */ pBlock = (PRTHEAPOFFSETBLOCK)pv - 1; pHeapInt = RTHEAPOFF_GET_ANCHOR(pBlock); ASSERT_BLOCK_USED(pHeapInt, pBlock); ASSERT_ANCHOR(pHeapInt); Assert(pHeapInt == (PRTHEAPOFFSETINTERNAL)hHeap || !hHeap); /* * Calculate the block size. */ cbBlock = (pBlock->offNext ? pBlock->offNext : pHeapInt->cbHeap) - RTHEAPOFF_TO_OFF(pHeapInt, pBlock) - sizeof(RTHEAPOFFSETBLOCK); return cbBlock; }
RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE hHeap, void *pv) { PRTHEAPSIMPLEINTERNAL pHeapInt; PRTHEAPSIMPLEBLOCK pBlock; size_t cbBlock; /* * Validate input. */ if (!pv) return 0; AssertPtrReturn(pv, 0); AssertReturn(RT_ALIGN_P(pv, RTHEAPSIMPLE_ALIGNMENT) == pv, 0); /* * Get the block and heap. If in strict mode, validate these. */ pBlock = (PRTHEAPSIMPLEBLOCK)pv - 1; pHeapInt = pBlock->pHeap; ASSERT_BLOCK_USED(pHeapInt, pBlock); ASSERT_ANCHOR(pHeapInt); Assert(pHeapInt == (PRTHEAPSIMPLEINTERNAL)hHeap || !hHeap); /* * Calculate the block size. */ cbBlock = (pBlock->pNext ? (uintptr_t)pBlock->pNext : (uintptr_t)pHeapInt->pvEnd) - (uintptr_t)pBlock- sizeof(RTHEAPSIMPLEBLOCK); return cbBlock; }
RTDECL(size_t) RTHeapOffsetGetFreeSize(RTHEAPOFFSET hHeap) { PRTHEAPOFFSETINTERNAL pHeapInt; if (hHeap == NIL_RTHEAPOFFSET) return 0; pHeapInt = hHeap; AssertPtrReturn(pHeapInt, 0); ASSERT_ANCHOR(pHeapInt); return pHeapInt->cbFree; }
RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE hHeap) { PRTHEAPSIMPLEINTERNAL pHeapInt; if (hHeap == NIL_RTHEAPSIMPLE) return 0; pHeapInt = hHeap; AssertPtrReturn(pHeapInt, 0); ASSERT_ANCHOR(pHeapInt); return pHeapInt->cbFree; }
RTDECL(void) RTHeapOffsetFree(RTHEAPOFFSET hHeap, void *pv) { PRTHEAPOFFSETINTERNAL pHeapInt; PRTHEAPOFFSETBLOCK pBlock; /* * Validate input. */ if (!pv) return; AssertPtr(pv); Assert(RT_ALIGN_P(pv, RTHEAPOFFSET_ALIGNMENT) == pv); /* * Get the block and heap. If in strict mode, validate these. */ pBlock = (PRTHEAPOFFSETBLOCK)pv - 1; pHeapInt = RTHEAPOFF_GET_ANCHOR(pBlock); ASSERT_BLOCK_USED(pHeapInt, pBlock); ASSERT_ANCHOR(pHeapInt); Assert(pHeapInt == (PRTHEAPOFFSETINTERNAL)hHeap || !hHeap); #ifdef RTHEAPOFFSET_FREE_POISON /* * Poison the block. */ const size_t cbBlock = (pBlock->pNext ? (uintptr_t)pBlock->pNext : (uintptr_t)pHeapInt->pvEnd) - (uintptr_t)pBlock - sizeof(RTHEAPOFFSETBLOCK); memset(pBlock + 1, RTHEAPOFFSET_FREE_POISON, cbBlock); #endif /* * Call worker which does the actual job. */ rtHeapOffsetFreeBlock(pHeapInt, pBlock); }