Posix shared memory vs mapped files

一个人想着一个人 提交于 2019-12-02 16:41:30

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.

The use of the mmap() function is restricted by the QSHRMEMCTL System Value. When this system value is 0, the mmap() function may not create a shared mapping having with PROT_WRITE capability. Essentially, this prevents the creation of a memory map that could alter the contents of the stream file being mapped. If the flags parameter indicated MAP_SHARED, the prot parameter specifies PROT_WRITE and the QSHRMEMCTL system value is 0, then the mmap() functions will fail and an error number of EACCES results.

Rajat Paliwal

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!