I have been looking into using Boost.Interprocess to create a disk-backed data structure. The examples on Boost Documentation (http://www.boost.org/doc/libs/1_41_0/doc/html/interprocess.html) are all for using shared memory even though they mention that memory mapped files can also be used. I am wondering whether anyone here has used memory mapped files? Any publicly available code samples to get started (say, a memory mapped file backed map or set)?
A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory.
Accessing memory mapped files is faster than using direct read and write operations for two reasons. Firstly, a system call is orders of magnitude slower than a simple change to a program's local memory.
Memory mapping of files is a very powerful abstraction that many operating systems support out of the box. Linux does this via the mmap system call. In most cases where an application reads (or writes) to a file at arbitrary positions, using mmap is a solid alternative to the more traditional read / write system calls.
File mapping is the association of a file's contents with a portion of the address space of a process. The system creates a file mapping to associate the file and the address space of the process. A mapped region is the portion of address space that the process uses to access the file's contents.
You might take look at stldb project that's being actively discussed on boost mail list. It tries to build an ACID database on top of boost::interprocess
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With