2

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

IInspectable
  • 46,945
  • 8
  • 85
  • 181
Paul
  • 443
  • 8
  • 18
  • Note that I updated the tags to include C++ and winapi as these are key to categorizing your question, more so than "memory" and "leak". – Jonathon Reinhart May 15 '13 at 07:27

1 Answers1

4

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.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • @Jonathan. Is it possible to access this function using C#? It seems I'm not the only person who would like to know this: http://stackoverflow.com/questions/9799147/get-memory-space-in-c-sharp Thanks again. – Paul May 22 '13 at 08:58
  • @pau The Win32 API is made available to .NET through [C#/Win32](https://github.com/microsoft/CsWin32). – IInspectable May 04 '22 at 09:03