如果从卸载的 MappedByteBuffer 中读取数据会发生什么?

发布于 2025-01-16 06:51:54 字数 384 浏览 0 评论 0原文

如果您读/写 MappedByteBuffer 已卸载?

手术会失败吗?与内存映射文件相比,它读取/写入底层文件的速度是否会更慢?它会触发 load() 然后进行读/写吗?

规范似乎没有指出某种方式,但同时也没有表明 get()put() 可能会为此抛出异常所以我不确定会发生什么。

我更喜欢由规范驱动的答案,而不是查看将来可能会发生变化的底层源代码。

What happens if you read/write into MappedByteBuffer that is unloaded?

Will the operation fail? Will it read/write the underlying file more slowly than it would if the file was memory-mapped? Will it trigger a load() followed by the read/write?

The specification does not seem to indicate one way or another, but at the same time it doesn't indicate that get() and put() may throw an exception for this case so I'm not sure what to expect.

I would prefer an answer driven by the specification as opposed to peeking at the underlying source-code that may change in the future.

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

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

发布评论

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

评论(1

好久不见√ 2025-01-23 06:51:54

重新阅读规范, isLoaded() 并不指示文件是否“未映射”,而是指示内存映射可能已被换出。

因此,假设我正确理解这一点,任何后续的读/写都会触发页面错误,从而将映射重新加载到物理内存中。

Re-reading the specification, isLoaded() does not indicate whether the file was "unmapped" but rather that the memory-map might have been swapped out.

So, assuming I understand this correctly, any subsequent reads/writes will trigger page faults which will reload the map into physical memory.

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