内存映射文件:如何监控内存使用情况
我正在开发一个需要大量内存的 32 位最终用户应用程序。高达数千兆字节。我最近将内部内存分配策略切换为使用内存映射文件无文件,灵感来自于 这篇 Raymond Chen 文章。效果很好。
唯一的缺点是:如果我以这种方式分配一千兆字节的内存,它不会显示在性能计数器中的任何位置。当然,我确实知道分配了多少,以及有多少映射到我的地址空间,但我不知道它是如何在物理内存和页面文件上划分的。我想知道,如果不是出于任何其他原因而不是记录它进行调试。
I work on a 32 bit end user application that needs a lot of memory. Up to several gigabytes. I recently switched our internal memory allocation strategy to use memory-mapped-files-without-files inspired by this Raymond Chen article. It works great.
The only downside is this: If I allocate a gigabyte of memory this way, it does not show up anywhere in the performance counters. Of course, I do know how much is allocated, and how much of it is mapped into my adress space, but I don't know how it's divided over physical memory and the page file. I would like to know, if not for any other reason than logging it for debugging.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用 QueryWorkingSet 并计算映射范围内的页面数确定有多少内存属于工作集。但请记住,页面可能会从工作集中排除,但仍位于物理内存中的某个位置。
Call QueryWorkingSet and count the number of pages that lie within your mapped range to determine how much of your memory is part of the working set. But keep in mind that pages could be excluded from the working set but still be in physical memory somewhere.
解决方案是使用 sysinternals 的 VMMap 监视我的应用程序。这可以按分配类型(我的内存映射文件称为“共享”)以及状态(在内存中或已换出)来细分应用程序的内存使用情况。
甚至还有一个图形内存碎片图!
The solution was to monitor my application with sysinternals' VMMap. This breaks down an applications memory usage by allocation type (my memory mapped files are called "shared"), as well as by status (in memory or swapped out).
There's even a graphical memory fragmentation map!