-1

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

trincot
  • 317,000
  • 35
  • 244
  • 286
Maksim
  • 191
  • 1
  • 10
  • 1
    Hmm... `valgrind` on Linux tells you total usage; perhaps with some tweaking you can get it to separate allocations and deallocations. GCC 4.6.2 prints out stack usage as well (statically). – Kerrek SB Nov 10 '11 at 17:07
  • `valgrind --tool=massif` does a great job on linux (if it's possible to set up a linux VM and run your code there): http://valgrind.org/docs/manual/ms-manual.html – Aria Buckles Nov 10 '11 at 18:29

3 Answers3

2

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.

Wisdom's Wind
  • 1,448
  • 9
  • 10
Sam Holloway
  • 1,999
  • 15
  • 14
0

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).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
0

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.

Community
  • 1
  • 1
Joe McGrath
  • 1,481
  • 10
  • 26