对一个文件调用两次 mmap

发布于 2025-01-04 06:59:06 字数 144 浏览 3 评论 0原文

我想随机访问大文件的某些部分。使用 mmap 打开我需要的部分后,如果我需要文件的另一部分。我应该再次关闭第一个内存映射区域和 mmap 还是可以同时打开两个内存映射区域?

我不想映射所有文件,因为它可能大于 RAM,并且我将在程序中使用同时打开的多个文件。

I want to reach parts of a large file randomly. After opening the part I needed with mmap if I need another part of the file. Should I close the first memory mapped region and mmap again or can I open two memory mapped region at the same time?

I don't want to map all the file since it could be larger than the RAM and I will use multiple files open at the same time on my program.

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

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

发布评论

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

评论(1

梦晓ヶ微光ヅ倾城 2025-01-11 06:59:06

Mmapping 不消耗 RAM。您可以而且应该映射整个文件,除非它大于可用的地址空间。在 64 位计算机上,这是不太可能的。在 32 位上,这并非不可能。

在任何情况下,您都可以对每个文件进行任意数量的映射。

Mmapping does not consume RAM. You can and should map the entire file unless it is larger than the available address space. On a 64-bit computer, that's rather unlikely. On 32-bits, it's not impossible.

In any case, you can make as many mappings as you want of each single file.

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