对一个文件调用两次 mmap
我想随机访问大文件的某些部分。使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.