Kaynağa Gözat

cmLinkHeap.h/c : Added cmLHeapIsPtrInHeap().

master
kpl 10 yıl önce
ebeveyn
işleme
5464cbf4e4
2 değiştirilmiş dosya ile 27 ekleme ve 0 silme
  1. 24
    0
      cmLinkedHeap.c
  2. 3
    0
      cmLinkedHeap.h

+ 24
- 0
cmLinkedHeap.c Dosyayı Görüntüle

100
   return _cmLHeapAlloc(p,byteCnt);
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
 bool     _cmLHeapFree(    cmLHeap_t* lhp, void* dataPtr )
117
 bool     _cmLHeapFree(    cmLHeap_t* lhp, void* dataPtr )
104
 { 
118
 { 
105
   if( dataPtr == NULL )
119
   if( dataPtr == NULL )
106
     return true;
120
     return true;
107
 
121
 
122
+  /*
108
   cmLhBlock_t* lbp = lhp->first;
123
   cmLhBlock_t* lbp = lhp->first;
109
 
124
 
110
   // locate the block containing the area to free
125
   // locate the block containing the area to free
111
   while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
126
   while( (lbp != NULL ) && (((char*)dataPtr < lbp->basePtr) || ((char*)dataPtr >= lbp->endPtr)))
112
     lbp = lbp->nextBlkPtr;
127
     lbp = lbp->nextBlkPtr;
128
+  */
129
+
130
+  cmLhBlock_t* lbp = _cmLHeapPtrToBlock(lhp,dataPtr);
113
 
131
 
114
   // the pointer must be in one of the blocks
132
   // the pointer must be in one of the blocks
115
   if( lbp == NULL )
133
   if( lbp == NULL )
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
 cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags )
323
 cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags )
300
 {
324
 {
301
   cmLHeap_t*   lhp = _cmLHeapHandleToPtr(h);
325
   cmLHeap_t*   lhp = _cmLHeapHandleToPtr(h);

+ 3
- 0
cmLinkedHeap.h Dosyayı Görüntüle

37
   // release the associated memory, otherwise releases all memory blocks.
37
   // release the associated memory, otherwise releases all memory blocks.
38
   void       cmLHeapClear(   cmLHeapH_t h, bool releaseFl );
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
   // mmFlags take the same values as the flags parameter to cmMmReport().
43
   // mmFlags take the same values as the flags parameter to cmMmReport().
41
   cmMmRC_t   cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags );
44
   cmMmRC_t   cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags );
42
   void       cmLHeapReport(  cmLHeapH_t h );
45
   void       cmLHeapReport(  cmLHeapH_t h );

Loading…
İptal
Kaydet