Boost :: round_buffer equivalent for files?

I am looking for a library that allows you to get a circular buffer on disk.
There is something similar in Boost, but it is a container with memory: circular_buffer .

+1
c ++ boost disk circular-buffer
source share
1 answer

You can call it what you think is natural.

You are looking for memory mapped files.

Using the right allocator, you can create containers in this area with memory mapping. This will make the container "on disk".

I will see if Boost Circularbuffer supports this directly.

Refresh Yes.

Best of all, it gives you the full ability to even use IPC synchronization and thread synchronization. Using the "private" memory card, you can map the buffer to read and write without writing changes to disk in some processes.

Proof of concept:

Live On Coliru ยน

#include <boost/circular_buffer.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/managed_mapped_file.hpp> namespace bip = boost::interprocess; struct message { int data[32]; }; int main() { bip::managed_mapped_file mmf(bip::open_or_create, "/tmp/circ_buffer.bin", 4ul << 20); typedef bip::allocator<message, bip::managed_mapped_file::segment_manager> allocator; boost::circular_buffer<message, allocator> instance(100, mmf.get_segment_manager()); } 

ยน In Coliru, the file size is understandably limited.

+6
source share

All Articles