Search code examples
c++windowsmemorydiagnosticsmsvcrt

How to get detailed diagnostics from CRT Memory Manager in Windows?


For the purposes of debugging and diagnosing memory fragmentation, I'd like to be able to query the memory manager (the default one provided for C++ applications) for certain information, such as the number of non-contiguous free blocks and the size of each of those.

I envision a way to essentially scan or iterate the entire heap from beginning to end and look at the details of everything. If I see a chunk of non-free memory here, how big is that in bytes? Next, I may encounter a free block, how big is that one?

I've tried swapping out our memory manager with something from a third party, but as of right now our code base is too complex, and I kept getting crashes, even though I tried various tricks. So I have to either depend on some CRT heap diagnostic functions to do this or some tool that will do it for me.

Help (and code examples in C++) is appreciated!


Solution

  • From the sound of things, you're looking for _heapwalk. The linked page includes a small demonstration.