提高:: circular_buffer相当于文件? [英] boost::circular_buffer equivalent for files?

查看:160
本文介绍了提高:: circular_buffer相当于文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个库,允许获得磁盘上的循环缓冲区。结果
在升压有类似的东西,但它是一个在内存中基于容器:的 circular_buffer

I am looking for a library which allows to get a circular buffer on disk.
In Boost there is something similar, but it is an in memory based container: circular_buffer.

推荐答案

您可以称它为任何你觉得是很自然的。

You can call it whatever you think is natural.

您正在寻找的内存映射文件。

You're looking for memory mapped files.

使用正确的分配器,可以使容器在此内存映射区域分配。这将使磁盘的容器。

Using the right allocator, you can make containers be allocating in this memory mapped region. That would make the container "on disk".

<击>我会看到升压环形缓冲区是否支持此直接。

更新

最好的事情是,这给你充分的可能性,甚至使用IPC同步和线程同步。使用私有内存映射,你可以映射缓冲区可读写,而不在一些过程的变化写回磁盘。

The best thing is, this gives you full possibility to even use IPC synchronization and thread synchronization. Using a "private" memory map you could map the buffer read-writable without writing changes back to disk in some of the processes.

概念验证:

<大骨节病> 住在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());
}


¹在Coliru文件大小是 - 可以理解的约束


¹ On Coliru the filesize is - understandably constrained.

这篇关于提高:: circular_buffer相当于文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆