Posix 共享内存与映射文件
了解了一些关于这个主题的知识后,谁能告诉我,POSIX 共享内存 (shm_open) 和 POSIX 映射文件 (mmap) 之间的真正区别是什么?
两者似乎都使用 /dev/tmpfs 子系统,而不是旧的 IPC 机制。
那么使用 mmap 文件比共享内存有什么优势吗?
谢谢。
Having learnt a bit about the subject, can anyone tell, what is the real difference between POSIX shared memory (shm_open) and POSIX mapped files (mmap)?
Both seems to use the /dev/tmpfs subsystem, rather then older IPC mechanism.
So is there any advantage of using mmap file over shared memory?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上共享内存是 IPC 的一种形式。共享区域是在 /dev/shm 中创建的,它仅在内存(RAM)中创建,并且不需要磁盘操作,因此它是一种更快的 IPC 方法。尽管 IPC 可以使用以下方式完成磁盘文件,然后也使用 mmap,但它会相对较慢。或者,您始终可以将 MAP_ANONYMOUS 与 mmap 一起使用,它不备份任何磁盘文件。
Basically shared memory is an form of IPC.The shared region is created in /dev/shm which is created in memory only(RAM) and it requires no disk operations, hence it is a faster method of IPC.Although IPC can be done using disk file and then using mmap too, but it would be comparetively slow.Alternatively you can always use MAP_ANONYMOUS with mmap which does not back up with any disk file.
区别并不总是很清楚。共享内存可以通过内存映射文件来实现。 可以在这里找到关于此的优秀文章(如适用于 C/C++ 编程)。
The distinction is not always clear. Shared memory can be implemented via memory mapped files. An excellent write on this can be found here (as applied to C/C++ programming).
我的理解是,共享内存构建在映射文件之上,但是 此页面似乎表明使用内存映射文件作为共享内存的能力是有条件的。
My understanding is that that shared memory is built on top of mapped files, but This Page seems to indicate that the ability to use memory mapped files as shared memory is conditional.