我如何告诉Windows保留页面而不将其逐出? [英] How can I tell Windows to keep a page and not evict it?

查看:90
本文介绍了我如何告诉Windows保留页面而不将其逐出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows 中分配一块内存,并确保它不会出现#GP或#PF错误.关于#GP,作为程序员,我有责任确保不超出任何范围.但是,#PF是操作系统的责任,因为它可以选择是否逐出页面.

I want to allocate a chunk of memory in Windows and be sure that it will get no #GP or #PF faults. Regarding #GP, it's my responsibility as a programmer to ensure that I do not exceed any bounds. However, #PF are the the responsibility of the OS, since it can choose whether or not to evict a page.

我想像一下,如果我经常使用同一页面,那么该操作系统将足够聪明以至于无法逐出该页面.但是,如果我想分配一个大的内存块,那么我将花一些时间才能到达某些页面,并且我不希望OS在此同时退出它.

I imagine that if I use the same page frequently, the OS will be smart enough not to evict it. However, if I want to allocate a large block of memory, then it'll take me a while to reach some of the pages, and I don't want the OS to evict it in the meanwhile.

有什么办法让 Windows 保持页面显示状态,从而使我永远不会出现页面错误?

Is there any way to tell Windows to keep a page present so that I never get a page fault?

ote:这类似于问题

ote: This is similar to to the question How can I tell Linux to keep a page and not evict it? except that this one is about Windows

推荐答案

看看 VirtualLock 功能:

将进程的虚拟地址空间的指定区域锁定到物理内存中,以确保对区域的后续访问不会引起页面错误.

Locks the specified region of the process's virtual address space into physical memory, ensuring that subsequent access to the region will not incur a page fault.

此页面中有一个示例:创建保护页面.

There's an example in this page: Creating Guard Pages.

这篇关于我如何告诉Windows保留页面而不将其逐出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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