How to get memory usage under Windows in C++(如何在C++中获取Windows下的内存使用情况)
问题描述
我试图从程序本身中找出我的应用程序消耗了多少内存.我要查找的内存使用情况是 Windows 任务管理器进程"选项卡上内存使用情况"列中报告的数字.
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.
推荐答案
一个好的起点是 GetProcessMemoryInfo,报告有关指定进程的各种内存信息.您可以将 GetCurrentProcess()
作为进程句柄传递,以获取有关调用进程的信息.
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.
可能 PROCESS_MEMORY_COUNTERS
的 WorkingSetSize
成员与任务管理器中的 Mem Usage coulmn 最接近,但它不会完全相同.我会尝试使用不同的值来找到最接近您需求的值.
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.
这篇关于如何在C++中获取Windows下的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在C++中获取Windows下的内存使用情况


基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30