Procházet zdrojové kódy

cmLinkHeap.h/c : Added cmLHeapIsPtrInHeap().

master
kpl před 11 roky
rodič
revize
5464cbf4e4
2 změnil soubory, kde provedl 27 přidání a 0 odebrání
  1. 24
    0
      cmLinkedHeap.c
  2. 3
    0
      cmLinkedHeap.h

+ 24
- 0
cmLinkedHeap.c Zobrazit soubor

@@ -100,16 +100,34 @@ void* _cmLHeapAllocCb(void* funcArgPtr, unsigned byteCnt)
100 100
   return _cmLHeapAlloc(p,byteCnt);
101 101
 }
102 102
 
103
+cmLhBlock_t* _cmLHeapPtrToBlock( cmLHeap_t* lhp, const void* dataPtr )
104
+{
105
+  if( dataPtr == NULL )
106
+    return NULL;
107
+
108
+  cmLhBlock_t* lbp = lhp->first;
109
+
110
+  // locate the block containing the area to free
111
+  while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
112
+    lbp = lbp->nextBlkPtr;
113
+
114
+  return lbp;
115
+}
116
+
103 117
 bool     _cmLHeapFree(    cmLHeap_t* lhp, void* dataPtr )
104 118
 { 
105 119
   if( dataPtr == NULL )
106 120
     return true;
107 121
 
122
+  /*
108 123
   cmLhBlock_t* lbp = lhp->first;
109 124
 
110 125
   // locate the block containing the area to free
111 126
   while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
112 127
     lbp = lbp->nextBlkPtr;
128
+  */
129
+
130
+  cmLhBlock_t* lbp = _cmLHeapPtrToBlock(lhp,dataPtr);
113 131
 
114 132
   // the pointer must be in one of the blocks
115 133
   if( lbp == NULL )
@@ -296,6 +314,12 @@ void       cmLHeapClear(   cmLHeapH_t h, bool releaseFl )
296 314
   }
297 315
 }
298 316
 
317
+bool cmLHeapIsPtrInHeap( cmLHeapH_t h, const void* ptr )
318
+{
319
+  cmLHeap_t*   lhp = _cmLHeapHandleToPtr(h); 
320
+  return _cmLHeapPtrToBlock(lhp,ptr) != NULL;
321
+}
322
+
299 323
 cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags )
300 324
 {
301 325
   cmLHeap_t*   lhp = _cmLHeapHandleToPtr(h);

+ 3
- 0
cmLinkedHeap.h Zobrazit soubor

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

Načítá se…
Zrušit
Uložit