It is so simple:
#include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> // ... int fd = open("memfile.txt",O_RDWR); struct stat info; fstat(fd, &info); void * page = mmap(0, info.st_size, PROT_READ , MAP_SHARED, fd, 0);
Now you can use everything that you saved in memfile.txt as a structure, and it will be shared between processes.
NOTE , as others have stated, you cannot use pointers between objects inside this piece of memory.
This works for me on OS X 10.4, but should work on any BSD-compatible system.
source share