Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get memory usage under Windows in C++

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.

like image 761
Brian Stewart Avatar asked Nov 11 '08 21:11

Brian Stewart


People also ask

How do I check Windows memory usage?

Press Ctrl + Shift + Esc to launch Task Manager. Or, right-click the Taskbar and select Task Manager. Select the Performance tab and click Memory in the left panel. The Memory window lets you see your current RAM usage, check RAM speed, and view other memory hardware specifications.

How do I find out how much virtual memory I have Windows 10?

Virtual Memory or Page File size can be viewed/modified through System Properties > Advanced tab > Performance Settings > Advanced tab > Virtual Memory section (left screenshot, below).

What is using memory Windows 10?

In the full Task Manager window, navigate to the “Processes” tab. You'll see a list of every application and background task running on your machine. Collectively, those programs are called “processes.” To sort the processes by which one is using the most memory, click the “Memory” column header.


1 Answers

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.

like image 184
Charlie Avatar answered Sep 22 '22 09:09

Charlie