mmap()
An alternative to shared memory is memory mapped i/o, which maps a file on disk into a buffer in memory, so that when bytes are fetched from the buffer the corresponding bytes of the file are read
One advantage is that the contents of files are non-volatile
Usage:
caddr_t mmap( caddr_t addr, size_t len, int
prot, int flag, int filedes, off_t off );
- addr and off should be set to zero,
- len is the number of bytes to allocate
- prot is the file protection, typically (PROT_READ|PROT_WRITE)
- flag should be set to MAP_SHARED to emulate shared memory
- filedes is a file descriptor that should be opened previously