本文介绍了远离虚拟内存在Windows\C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个性能关键的应用程序,其中必须在物理内存中存储尽可能多的数据,然后转储到磁盘。

I'm writing a performance critical application where its essential to store as much data as possible in the physical memory before dumping to disc.

我可以使用 :: GlobalMemoryStatusEx(...) :: GetProcessMemoryInfo ...),以找出保留的物理内存的百分比\ free,以及我当前进程处理的内存量。
使用这个数据,我可以确保当〜90%的物理内存正在使用或者〜90的最大2GB每应用程序限制被击中时转储。

I can use ::GlobalMemoryStatusEx(...) and ::GetProcessMemoryInfo(...) to find out what percentage of physical memory is reserved\free and how much memory my current process handles.Using this data I can make sure to dump when ~90% of the physical memory is in use or ~90 of the maximum of 2GB per application limit is hit.

然而,我想要一个方法来简单地接收在系统开始使用虚拟内存之前剩下多少字节,特别是因为应用程序将针对32位和64位进行编译,而2 GB限制不存在。

However, I would like a method for simply recieving how many bytes are actually left before the system will start using the virtual memory, especially as the application will be compiled for both 32bit and 64bit, whereas the 2 GB limit doesnt exist.

推荐答案

即使您能够停止应用程序将内存分页到磁盘,您仍然会遇到问题,VMM可能会调出其他程序到磁盘,并可能会影响您的性能。更不用说另一个应用程序可能会启动并消耗您当前占用的内存,从而导致您的一些应用程序内存被分页。您计划如何处理这个问题?

Even if you're able to stop your application from having memory paged out to disk, you'll still run into the problem that the VMM might be paging out other programs to disk and that might potentially affect your performance as well. Not to mention that another application might start up and consume memory that you're currently occupying and thus resulting in some of your applications memory being paged out. How are you planning to deal with that?

有一种方法可以通过,但(a)这个池比较小,(b)它被设备驱动程序使用,并且可能只可以从内核使用。它也不是真的建议使用它的大块,除非你想确保你的系统是不稳定。

There is a way to use non-pageable memory via the non-paged pool but (a) this pool is comparatively small and (b) it's used by device drivers and might only be usable from inside the kernel. It's also not really recommended to use large chunks of it unless you want to make sure your system isn't that stable.

你可能想重新访问你的应用程序的设计并尝试解决将内存分页到磁盘的可能性,然后尝试编写自己的VMM或将Windows机器转换为基本上具有更多内存的DOS框。

You might want to revisit the design of your application and try to work around the possibility of having memory paged to disk before you either try to write your own VMM or turn a Windows machine into essentially a DOS box with more memory.

这篇关于远离虚拟内存在Windows\C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:29