In the UNIX world, the standard way to create a file mapping object supported by RAM or a page file, rather than a disk file, is to call shm_open. This creates a memory mapping with the name and returns a file descriptor that you can pass to mmap.
The problem is that it creates a name. It would be nice if I could create an anonymous memory mapping. This would solve two problems:
- This will avoid problems when two instances of the same program can stomp each other in the mapped files.
- If a program crashes or otherwise abruptly terminates, it will not leave a shared memory object. Calling
shm_unlinkimmediately after shm_openis one of the possibilities, but it leaves a small window in which a sudden termination will leave the object around until the next reboot.
Linux exists memfd_createto solve this problem. Similarly, Windows allows you to pass a null name CreateFileMappingWto create an anonymous mapping.
Is there an equivalent for Mac OS?
Myria source
share