如何使用 WinAPI 锁定内存中的页面?
我需要防止应用程序的内存页面在 Windows 上从 RAM 中换出。是否有与 POSIX 等效的 WinAPI 函数 mlockall()
达到这个目的?
I need to prevent application's memory pages from being swapped out of RAM on Windows. Is there a WinAPI function equivalent of POSIX mlockall()
to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,VirtualLock()。您可以锁定的页面数量是有限制的,您不能占用内存。详细信息请参阅 MSDN 文章。
Yes, VirtualLock(). There's a limit on how many pages you can lock, you can't hog RAM. Details are in the MSDN article.
我不得不问,为什么需要这样做?如果每个应用程序都认为其页面非常重要以至于不应该被调出,那么这将是对内存的巨大浪费。
如果页面正在使用中,它们不会被发送到页面文件,如果它们没有在使用中,为什么还要保留它们呢?相信嗯,它是由一个非常聪明的人编写的 :)
I have to ask, why do you need to do this? If every app thought its pages were so important that they shouldn't be paged out ever, it would be a giant waste of memory.
If the pages are in use, they won't be sent to the pagefile, and if they're not in use, why keep them around? Trust in Mm, it was written by a very smart guy :)
您好,您可以设置内存中锁定页面的 Windows 选项。通常此设置主要由 SQL Server 使用,但也适用于其他应用程序。请在 msdn 上查看此网站,
为您的设备启用寻址 Windows 扩展 (AWE)应用。请参阅 msdn 上的此链接
Hi you can set the windows option of lock pages in memory. Usually this setting is mostly used by SQL Server, but works also for other applications. Check this site on msdn
enable addressing windows extensions (AWE) for your application. See this link on msdn