Depends how you're counting the bytes. If you're just counting the dwCommittedSize of the HEAP_REGION blocks you'll miss the big blocks since they are counted as seperate regions but not tagged as such (it's described in the PROCESS_HEAP_ENTRY::iRegionIndex docs). Summing up the cbData member of all PROCESS_HEAP_ENTRY_BUSY blocks will get you an accurate committed byte count.
Maybe this'll help:
Code:
void DisplayHeapsInfo(std::ostream& out = std::cout)
{
std::vector<HANDLE> heaps(GetProcessHeaps(0, NULL));
GetProcessHeaps(heaps.size(), &heaps[0]);
DWORD totalBytes = 0;
for(DWORD i = 0; i < heaps.size(); ++i)
{
out << "Heap handle: 0x" << heaps[i] << '\n';
PROCESS_HEAP_ENTRY phi = {0};
while(HeapWalk(heaps[i], &phi))
{
out << "Block Start Address: 0x" << phi.lpData << '\n';
out << "\tSize: " << phi.cbData << " - Overhead: "
<< static_cast<DWORD>(phi.cbOverhead) << '\n';
out << "\tBlock is a";
if(phi.wFlags & PROCESS_HEAP_REGION)
{
out << " VMem region:\n";
out << "\tCommitted size: " << phi.Region.dwCommittedSize << '\n';
out << "\tUncomitted size: " << phi.Region.dwUnCommittedSize << '\n';
out << "\tFirst block: 0x" << phi.Region.lpFirstBlock << '\n';
out << "\tLast block: 0x" << phi.Region.lpLastBlock << '\n';
}
else
{
if(phi.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE)
{
out << "n uncommitted range\n";
}
else if(phi.wFlags & PROCESS_HEAP_ENTRY_BUSY)
{
totalBytes += phi.cbData;
out << "n Allocated range: Region index - "
<< static_cast<unsigned>(phi.iRegionIndex) << '\n';
if(phi.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE)
{
out << "\tMovable: Handle is 0x" << phi.Block.hMem << '\n';
}
else if(phi.wFlags & PROCESS_HEAP_ENTRY_DDESHARE)
{
out << "\tDDE Sharable\n";
}
}
else out << " block, no other flags specified\n";
}
out << std::endl;
}
}
out << "End of report - total of " << std::dec << totalBytes << " allocated" << std::endl;
}