bug 125641 Adding id r=dougt sr=sfraser

This commit is contained in:
dp%netscape.com 2002-02-18 22:59:58 +00:00
Родитель 3428bea73a
Коммит 6271baf01b
2 изменённых файлов: 23 добавлений и 6 удалений

Просмотреть файл

@ -79,9 +79,9 @@ nsRecyclingAllocator::nsRecycleTimerCallback(nsITimer *aTimer, void *aClosure)
}
nsRecyclingAllocator::nsRecyclingAllocator(PRUint32 nbucket, PRUint32 recycleAfter)
nsRecyclingAllocator::nsRecyclingAllocator(PRUint32 nbucket, PRUint32 recycleAfter, const char *id)
: mNBucket(nbucket), mRecycleTimer(nsnull), mRecycleAfter(recycleAfter), mTouched(0),
mNAllocations(0)
mNAllocations(0), mId(id)
{
NS_ASSERTION(mNBucket <= NS_MAX_BUCKETS, "Too many buckets. This will affect the allocator's performance.");
if (mNBucket > NS_MAX_BUCKETS)
@ -230,8 +230,8 @@ nsRecyclingAllocator::Malloc(PRUint32 bytes, PRBool zeroit)
// Warn if we are failing over to malloc and not storing it
// This says we have a misdesigned memory pool. The intent was
// once the pool was full, we would never fail over to calloc.
printf("nsRecyclingAllocator::malloc %d - FAILOVER 0x%p Memory pool has sizes: ",
bytes, ptr);
printf("nsRecyclingAllocator(%s) malloc %d - FAILOVER 0x%p Memory pool has sizes: ",
mId, bytes, ptr);
for (i = 0; i < mNBucket; i++)
{
printf("%d ", mMemBucket[i].size);
@ -260,6 +260,15 @@ nsRecyclingAllocator::Free(void *ptr)
}
}
#ifdef DEBUG_dp
// Warn if we are failing over to free
printf("nsRecyclingAllocator(%s) free - FAILOVER 0x%p Memory pool has sizes: ", mId, ptr);
for (i = 0; i < mNBucket; i++)
{
printf("%d ", mMemBucket[i].size);
}
printf("\n");
#endif
// Failover to free
free(ptr);
}
@ -273,7 +282,7 @@ void
nsRecyclingAllocator::FreeUnusedBuckets()
{
#ifdef DEBUG_dp
printf("DEBUG: nsRecyclingAllocator::FreeUnusedBuckets: ");
printf("DEBUG: nsRecyclingAllocator(%s) FreeUnusedBuckets: ", mId);
#endif
if (!mNAllocations)
return;

Просмотреть файл

@ -98,9 +98,17 @@ class NS_COM nsRecyclingAllocator {
// there is nothing to be freed.
PRInt32 mNAllocations;
// mId: a string for identifying the user of nsRecyclingAllocator
// User mainly for debug prints
const char *mId;
public:
nsRecyclingAllocator(PRUint32 nbucket, PRUint32 recycleAfter = NS_DEFAULT_RECYCLE_TIMEOUT);
// nbucket : number of buckets to hold. Capped at NS_MAX_BUCKET
// recycleAfter : Try recycling allocated buckets after this many seconds
// id : a string used to identify debug prints. Will not be released.
nsRecyclingAllocator(PRUint32 nbucket, PRUint32 recycleAfter = NS_DEFAULT_RECYCLE_TIMEOUT,
const char *id = NULL);
~nsRecyclingAllocator();
// Allocation and free routines