cmLinkHeap.h/c : Added cmLHeapIsPtrInHeap().

This commit is contained in:
kpl 2013-10-12 20:20:37 -07:00
parent 80498f4f79
commit 5464cbf4e4
2 changed files with 30 additions and 3 deletions

View File

@ -100,10 +100,10 @@ void* _cmLHeapAllocCb(void* funcArgPtr, unsigned byteCnt)
return _cmLHeapAlloc(p,byteCnt); return _cmLHeapAlloc(p,byteCnt);
} }
bool _cmLHeapFree( cmLHeap_t* lhp, void* dataPtr ) cmLhBlock_t* _cmLHeapPtrToBlock( cmLHeap_t* lhp, const void* dataPtr )
{ {
if( dataPtr == NULL ) if( dataPtr == NULL )
return true; return NULL;
cmLhBlock_t* lbp = lhp->first; cmLhBlock_t* lbp = lhp->first;
@ -111,6 +111,24 @@ bool _cmLHeapFree( cmLHeap_t* lhp, void* dataPtr )
while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr))) while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
lbp = lbp->nextBlkPtr; lbp = lbp->nextBlkPtr;
return lbp;
}
bool _cmLHeapFree( cmLHeap_t* lhp, void* dataPtr )
{
if( dataPtr == NULL )
return true;
/*
cmLhBlock_t* lbp = lhp->first;
// locate the block containing the area to free
while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
lbp = lbp->nextBlkPtr;
*/
cmLhBlock_t* lbp = _cmLHeapPtrToBlock(lhp,dataPtr);
// the pointer must be in one of the blocks // the pointer must be in one of the blocks
if( lbp == NULL ) if( lbp == NULL )
return false; return false;
@ -296,6 +314,12 @@ void cmLHeapClear( cmLHeapH_t h, bool releaseFl )
} }
} }
bool cmLHeapIsPtrInHeap( cmLHeapH_t h, const void* ptr )
{
cmLHeap_t* lhp = _cmLHeapHandleToPtr(h);
return _cmLHeapPtrToBlock(lhp,ptr) != NULL;
}
cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags ) cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags )
{ {
cmLHeap_t* lhp = _cmLHeapHandleToPtr(h); cmLHeap_t* lhp = _cmLHeapHandleToPtr(h);

View File

@ -37,6 +37,9 @@ extern "C" {
// release the associated memory, otherwise releases all memory blocks. // release the associated memory, otherwise releases all memory blocks.
void cmLHeapClear( cmLHeapH_t h, bool releaseFl ); void cmLHeapClear( cmLHeapH_t h, bool releaseFl );
// Return true if 'ptr' points into a linked heap block.
bool cmLHeapIsPtrInHeap( cmLHeapH_t h, const void* ptr );
// mmFlags take the same values as the flags parameter to cmMmReport(). // mmFlags take the same values as the flags parameter to cmMmReport().
cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags ); cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags );
void cmLHeapReport( cmLHeapH_t h ); void cmLHeapReport( cmLHeapH_t h );