Paul
Paul

Reputation: 463

How to retrieve committed memory via C++

I've found several answers to this question here on SO, but none that answers my question. I'm trying to track down some memory leaks in our unmanaged C++ application, and from reading the following, it seems that "Memory - Commit Size" is the best metric to use when monitoring memory usage: http://forum.sysinternals.com/virtual-private-bytes-and-working-set_topic18296.html

Here's the explanation of the various metrics reported by Windows Task Manager: http://windows.microsoft.com/en-us/windows-vista/what-do-the-task-manager-memory-columns-mean

I've found the following that describes how to retrieve the Working Set data for a named process: http://msdn.microsoft.com/en-us/library/76yt3c0w.aspx

System.Diagnostics.Process[] processes =
    System.Diagnostics.Process.GetProcessesByName(theprocessName);
System.Diagnostics.Process process = processes[0];

However, this mentions nothing about Committed Memory:

Can anyone help? Paul

Upvotes: 2

Views: 2873

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

It looks like you want to use GetProcessMemoryInfo. This populates a PROCESS_MEMORY_COUNTERS structure.

The key element of this structure you'll be interested in is

PagefileUsage The Commit Charge value in bytes for this process. Commit Charge is the total amount of memory that the memory manager has committed for a running process.

Upvotes: 4

Related Questions