1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0023006: Improvement to debug memory leaks and insufficient memory growths.

This commit is contained in:
skv 2012-03-12 19:05:53 +04:00 committed by bugmaster
parent 0f524ba023
commit 13b4230bdb
2 changed files with 9 additions and 13 deletions

View File

@ -470,16 +470,14 @@ Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFil
Standard_Size aTotAlloc = 0; Standard_Size aTotAlloc = 0;
for (int i = 0; i < MAX_ALLOC_SIZE; i++) for (int i = 0; i < MAX_ALLOC_SIZE; i++)
{ {
if (myArray[i].nbAlloc > 0) if (myArray[i].nbAlloc > 0 || myArray[i].nbFree > 0)
{ {
Standard_Integer nbLeft = myArray[i].nbAlloc - myArray[i].nbFree; Standard_Integer nbLeft = myArray[i].nbAlloc - myArray[i].nbFree;
if (nbLeft < 0)
nbLeft = 0;
int aSize = i + 1; int aSize = i + 1;
Standard_Size aSizeAlloc = myArray[i].nbAlloc * aSize; Standard_Size aSizeAlloc = myArray[i].nbAlloc * aSize;
Standard_Size aSizeLeft = nbLeft * aSize; ptrdiff_t aSizeLeft = nbLeft * aSize;
Standard_Size aSizePeak = myArray[i].nbLeftPeak * aSize; Standard_Size aSizePeak = myArray[i].nbLeftPeak * aSize;
fprintf(aRepFile, "%10d %10d %10d %10d %10Iu %10Iu %10Iu\n", aSize, fprintf(aRepFile, "%10d %10d %10d %10d %10Iu %10Id %10Iu\n", aSize,
myArray[i].nbAlloc, nbLeft, myArray[i].nbLeftPeak, myArray[i].nbAlloc, nbLeft, myArray[i].nbLeftPeak,
aSizeAlloc, aSizeLeft, aSizePeak); aSizeAlloc, aSizeLeft, aSizePeak);
if (aTotAlloc + aSizeAlloc < aTotAlloc) // overflow ? if (aTotAlloc + aSizeAlloc < aTotAlloc) // overflow ?
@ -488,7 +486,7 @@ Standard_Boolean OSD_MAllocHook::CollectBySize::MakeReport(const char* theOutFil
aTotAlloc += aSizeAlloc; aTotAlloc += aSizeAlloc;
} }
} }
fprintf(aRepFile, "%10s %10s %10s %10s%c%10Iu %10Iu %10Iu\n", "Total:", fprintf(aRepFile, "%10s %10s %10s %10s%c%10Iu %10Id %10Iu\n", "Total:",
"", "", "", (aTotAlloc == SIZE_MAX ? '>' : ' '), aTotAlloc, "", "", "", (aTotAlloc == SIZE_MAX ? '>' : ' '), aTotAlloc,
myTotalLeftSize, myTotalPeakSize); myTotalLeftSize, myTotalPeakSize);
fclose(aRepFile); fclose(aRepFile);
@ -512,13 +510,12 @@ void OSD_MAllocHook::CollectBySize::AllocEvent
{ {
myMutex.Lock(); myMutex.Lock();
int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1)); int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1));
if (myArray[ind].nbAlloc + 1 > 0) myArray[ind].nbAlloc++;
myArray[ind].nbAlloc++;
myTotalLeftSize += theSize; myTotalLeftSize += theSize;
int nbLeft = myArray[ind].nbAlloc - myArray[ind].nbFree; int nbLeft = myArray[ind].nbAlloc - myArray[ind].nbFree;
if (nbLeft > myArray[ind].nbLeftPeak) if (nbLeft > myArray[ind].nbLeftPeak)
myArray[ind].nbLeftPeak = nbLeft; myArray[ind].nbLeftPeak = nbLeft;
if (myTotalLeftSize > myTotalPeakSize) if (myTotalLeftSize > (ptrdiff_t)myTotalPeakSize)
myTotalPeakSize = myTotalLeftSize; myTotalPeakSize = myTotalLeftSize;
myMutex.Unlock(); myMutex.Unlock();
} }
@ -534,12 +531,11 @@ void OSD_MAllocHook::CollectBySize::FreeEvent
size_t theSize, size_t theSize,
long /*theRequestNum*/) long /*theRequestNum*/)
{ {
if (theSize > 0 && myTotalLeftSize >= theSize) if (theSize > 0)
{ {
myMutex.Lock(); myMutex.Lock();
int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1)); int ind = (theSize > MAX_ALLOC_SIZE ? MAX_ALLOC_SIZE-1 : (int)(theSize-1));
if (myArray[ind].nbFree + 1 > 0) myArray[ind].nbFree++;
myArray[ind].nbFree++;
myTotalLeftSize -= theSize; myTotalLeftSize -= theSize;
myMutex.Unlock(); myMutex.Unlock();
} }

View File

@ -128,7 +128,7 @@ public:
Standard_Mutex myMutex; Standard_Mutex myMutex;
Numbers* myArray; Numbers* myArray;
size_t myTotalLeftSize; ptrdiff_t myTotalLeftSize;
size_t myTotalPeakSize; size_t myTotalPeakSize;
size_t myBreakSize; size_t myBreakSize;
}; };