Reputation: 18944
I want to share memory between processes using mmap(). mmap() can be applied on a regular file, or on a POSIX shared memory file (shm_open). But what is the difference? The difference is surely not whether the disk is accessed:
Upvotes: 2
Views: 964
Reputation: 47243
One difference is that although shared memory might be written to disk, it will never be written to disk permanently. If you create a normal file, then it persists across reboots. If you create a shared memory object, it doesn't. It behaves quite like a temporary file in that respect.
Another difference is that "It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments". So, although a shared memory object has a file-like path, it need not actually appear in the filesystem.
Really, both of those differences are about decoupling from the filesystem. Files and shared memory objects are both bags of bytes which can be read and written, but files differ in that they are persisted in the filesystem.
Upvotes: 2