如何在Windows下在C ++中获取内存使用 [英] How to get memory usage under Windows in C++

查看:219
本文介绍了如何在Windows下在C ++中获取内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出我的应用程序从程序内部消耗了多少内存。我正在寻找的内存使用是在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.

WorkingSetSize 成员PROCESS_MEMORY_COUNTERS 是与任务管理器中的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.

这篇关于如何在Windows下在C ++中获取内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆