Why use SysV or POSIX shared memory vs mmap()?
If you have a parent/child relationship, it's perfectly fine to use mmap.
sysv_shm is the original unix implementation that allows related and unrelated processes to share memory. posix_shm standardized shared memory.
If you're on posix system without mmap, you'd use posix_shm. If you're on a unix without posix_shm you'd use sysv_shm. If you only need to share memory vs a parent/child you'd use mmap if available.
If memory serves, the only reason to use SysV/POSIX over mmap
is portability. In particularly older Unix systems don't support MAP_ANON
. Solaris, Linux, the BSDs and OS X do, however, so in practice, there's little reason not to use mmap
.
shm
in Linux is typically implemented via a /dev/shm
file that gets mmap
ped, so, performance should be equivalent -- I'd go with mmap
(w/MAP_ANON
and MAP_SHARED
as you mention) for simplicity, if I know portability is no issue as you say's the case for you.