有什么方法可以知道二进制/文件的特定部分此时是否在内存中?

发布于 2024-12-14 11:52:38 字数 99 浏览 5 评论 0原文

哪些 win32 API 对于编写工具很有用,如下所述:

我的目标是一个可用于检查/报告文件的特定部分是否位于内存 (RAM) 或虚拟内存(磁盘)中/可用的工具一会儿?

What win32 APIs are useful to code a tool as described here:

My goal is a tool that can be used to check/report if a specific part of a file is located/available in-memory (RAM) or in virtual memory (disk) at a moment ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是我的挚爱i 2024-12-21 11:52:38

虚拟查询 QueryWorkingSetEx 就是这样做的,特别是PSAPI_WORKING_SET_EX_BLOCK 中的锁定位。正如我最初错误地指出的那样,VirtualQuery 只是让您判断页面是否已提交等,而不是它们是否实际上位于物理 RAM 中。对于 Linux,它将是 mincore ,它只是返回一个字节向量(LSB == 1 对于核心)。

请注意,您获得的信息是快照,这意味着原则上该信息可能在函数返回时已经过时(很像 GetCurrentProcessorNumber)。
因此,请将这些信息视为(可能或多或少准确,但不可靠)提示,而不是保证。

VirtualQuery QueryWorkingSetEx does that, specifically the Locked bit in PSAPI_WORKING_SET_EX_BLOCK. VirtualQuery as I've incorrectly pointed out initially merely lets you tell whether pages are committed and such, not whether they're actually in physical RAM. For Linux, it would be mincore, which simply returns a byte vector (LSB == 1 for in-core).

Note that the information you get is a snapshot, which means the information may in principle already be outdated at the time the function returns (much like GetCurrentProcessorNumber).
So, treat the information as a (probably more or less accurate, but unreliable) hint, not a guarantee.

短暂陪伴 2024-12-21 11:52:38

不存在,原因很简单。当 API 函数返回时,答案可能会发生变化。 (此外,答案通常是“是的,是的”。)

Doesn't exist, for a simple reason. The answer could change while the API function returns. (Also, the answer often is "yes and yes".)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文