Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C++ Boost memory mapped files to create disk-back data structures

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)?

like image 762
kvs Avatar asked Jan 11 '10 14:01

kvs


People also ask

How does memory mapped file work?

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.

Is memory mapped io faster?

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.

What is memory mapped file in linux?

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.

What is a memory map c++?

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.


1 Answers

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.

like image 149
Nikolai Fetissov Avatar answered Oct 19 '22 17:10

Nikolai Fetissov