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++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
