boost::circular buffer等效于文件
boost::circular_buffer equivalent for files?
我正在寻找一个可以在磁盘上获得循环缓冲区的库
Boost中也有类似的东西,但它是一个基于内存的容器:circular _buffer。
您可以将其称为任何您认为自然的名称。
您正在查找内存映射文件。
使用正确的分配器,可以使容器在这个内存映射区域中进行分配。这将使容器"在磁盘上"。
我会看看Boost Circularbuffer是否直接支持这一点
更新是。
最棒的是,这为您提供了充分的可能性,甚至可以使用IPC同步和线程同步。使用"专用"内存映射,您可以将缓冲区映射为可读写,而无需在某些进程中将更改写回磁盘。
概念证明:
在Coliru上直播 cco
#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上,文件大小受到限制,这是可以理解的。
相关文章:
- 从对象文件(.o)在macos上制作归档文件(.a文件)
- 构造一个类似于JSON文件c++的字符串
- cmake:构建依赖于非源文件.Qt帮助生成
- 如何找出依赖于LIB文件的DLL列表?
- MMAP仅适用于小文件
- C++17 相当于 boost::文件系统::unique_path()
- g++ 未定义的引用,尽管符号存在于 *.so 文件中
- 我是否也应该包括 string.h,即使它存在于头文件中
- 函数别名,适用于头文件
- 如何添加相对于当前文件的头文件路径
- 对应于二进制文件的 PDB
- 适用于大文件和 512 KB 块的最快和轻量级哈希算法 [C,Linux,MAC,Windows]
- 如何检查哪些项目依赖于.cpp文件
- 如何防止源文件依赖于头文件中的包含
- CopyFile 不适用于环境字符串,但仅适用于放置文件的标准目录。无论如何要克服这个?
- 我在多映射中得到了两次相同的密钥,它只存在于文本文件中
- 读取相对于包含文件的文件
- 如何使用 libumem 查找堆损坏,而不依赖于'core'文件?
- 如何制作不依赖于 .so 文件的可执行二进制文件
- 当方法体位于头文件中时强制内联