878 Chapter 19 Memory Management
assert(false);
}
// Keep track of the maximum number of bytes allocated.
if (ms_uiNumBytes > ms_uiMaxAllocatedBytes)
{
ms_uiMaxAllocatedBytes = ms_uiNumBytes;
}
// Keep track of the distribution of sizes for allocations.
if (ms_bTrackSizes)
{
// Keep track of the largest block ever allocated.
if (uiSize > ms_uiMaxBlockSize)
{
ms_uiMaxBlockSize = uiSize;
}
unsigned int uiTwoPowerI = 1;
int i;
for (i = 0; i <= 30; i++, uiTwoPowerI <<= 1)
{
if (uiSize <= uiTwoPowerI)
{
ms_auiHistogram[i]++;
break;
}
}
if (i == 31)
{
ms_auiHistogram[i]++;
}
}
return (void*)pcAddr;
}
The function has a mixture of memory management and statistical gathering.
Let’s look at the memor y management first. Abstractly, a call to the global
new oper-
ator resolves to a request ...