4 ms·
I thought that was what mmap was for: http://en.wikipedia.org/wiki/Mmap http://en.wikipedia.org/wiki/Mmap. And compare http://beej.us/guide/bgipc/output/html/m
by jstclair 15y ago
I thought that was what mmap was for: http://en.wikipedia.org/wiki/Mmap http://en.wikipedia.org/wiki/Mmap.
And compare http://beej.us/guide/bgipc/output/html/multipage/mmap.html http://beej.us/guide/bgipc/output/html/multipage/mmap.html to http://beej.us/guide/bgipc/output/html/multipage/shm.html http://beej.us/guide/bgipc/output/html/multipage/shm.html
- HerraBRE 15y agoMmap just gives an alternate API - access the file contents as a memory buffer, not a file. Turns out the underlying mechanism is the same, and if you are happy with fseek(), read() and write(), you don't really need mmap at all.
- lobster_johnson 15y agoThat's true on Linux, but is it also true about other OSes? Also, this will map the file privately (MAP_PRIVATE), meaning every process gets its own copy in its address space, and any coordination will have to go through the IO subsystem to reach the other processes. Sharing with MAP_SHARED will save space by sharing the memory between processes. It's also possible to share memory not backed by a file, which is even more efficient.
- willvarfar 15y agoMmapped files are typically quicker than lots of fseeking and read()ing and write()ing because they avoid the non-trivial syscall overhead. This has been a very big driver in the adoption of mmapped files, even those not backed by disk.