I wonder if there is any tool to investigate peak heap contents?
For example, I have an application written on C++ (MSVS2005) and I want to know peak heap consumption and it's contents.
Regards, Maksim
I wonder if there is any tool to investigate peak heap contents?
For example, I have an application written on C++ (MSVS2005) and I want to know peak heap consumption and it's contents.
Regards, Maksim
You can explore a process's heap allocation and usage using WinDBG (see !heap command), part of the free collection of Microsoft's Debugging Tools for Windows. Google around for help on the usage, although the best reference I found was the standard reference book Advanced Windows Debugging.
You can use _heapwalk
to look through the blocks that current make up the heap -- just be aware that the result you get won't be precise.
Obviously, the blocks that are marked as being in use tell you about the space currently allocated on the heap, but not necessarily about the maximum. However, (at least assuming you haven't called _heapmin
), the free blocks in the heap are there because they were in use, but then freed.
Now, it's likely that not quite all of those were ever actually in use at exactly the same time. When a small block has been freed, and a larger block is requested, the smaller block usually won't be able to satisfy that request. At the same time, what you usually care about is the maximum memory that's being used by the heap, and the fact that some of that may be considered "free" at a given time doesn't necessarily matter a lot. As such, just adding up the sizes of all the blocks gives a fairly reasonable estimate of the maximum heap size the program used (with the input data you used, etc.)
The link for _heapwalk
has a bit of demo code. As it stands, the code isn't very useful, but it does show how to call the function, so it's mostly a matter of putting the data together into a single number (where the demo just prints out the data about each block separately).
There is a tool at below link that does what your looking for, and only what your looking for. http://www.nirsoft.net/utils/heap_memory_view.html
Tested and works on Windows 7 x64 in addition to Vista.