views:

5314

answers:

4

I am trying to find out how much memory my application is consuming from within the program itself. The memory usage I am looking for is the number reported in the "Mem Usage" column on the Processes tab of Windows Task Manager.

+7  A: 

A good starting point would be GetProcessMemoryInfo, which reports various memory info about the specified process. You can pass GetCurrentProcess() as the process handle in order to get information about the calling process.

Probably the WorkingSetSize member of PROCESS_MEMORY_COUNTERS is the closest match to the Mem Usage coulmn in task manager, but it's not going to be exactly the same. I would experiment with the different values to find the one that's closest to your needs.

Charlie
+3  A: 

GetProcessMemoryInfo is the function you are looking for. The docs on MSDN will point you in the right direction. Get the info you want out of the PROCESS_MEMORY_COUNTERS structure you pass in.

You'll need to include psapi.h.

+1  A: 

Try having a look at GetProcessMemoryInfo. I haven't used it, but it looks like what you need.

Mark Ransom
+1  A: 

Please look at my post here:

Search for ShaChris23

ShaChris23