How to retrieve committed memory via C++

2020-04-16 02:31发布

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

1条回答
地球回转人心会变
2楼-- · 2020-04-16 02:38

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.

查看更多
登录 后发表回答