我有一个长期运行的实验程序的内存占用,我想知道它的实际内存占用。任务管理器说(在 windows7-64 中)该应用程序正在消耗 800 mb 的内存,但根据任务管理器的说法,分配的内存总量为 3.7gb。所有分配内存的总和不等于 3.7gb。如何动态确定我的应用程序实际消耗了多少内存。
推论:任务管理器实际报告的内存是多少?似乎并不是所有内存都分配给了应用程序本身。
最佳答案
据我了解,任务管理器显示的是工作集;
working set: The set of memory pages recently touched by the threads of a process. If free memory in the computer is above a threshold, pages are left in the working set of a process even if they are not being used. When free memory falls below a threshold, pages are trimmed from the working set.
通过 http://msdn.microsoft.com/en-us/library/cc432779(PROT.10).aspx
您也可以让任务管理器显示虚拟内存。
我通常使用 perfmon (Start -> Run... -> perfmon) 来跟踪内存使用情况,使用 Private Bytes 计数器。它反射(reflect)了您的正常分配器(new/HeapAlloc/malloc 等)分配的内存。
关于windows - 我的 Windows 应用程序真正使用了多少内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1166502/