使用 Boost 在共享内存中创建循环缓冲区时出现问题

发布于 2024-08-22 21:13:49 字数 817 浏览 4 评论 0原文

我正在尝试使用 Boost circular_buffer 和 Interprocess 库在共享内存中创建循环缓冲区。我编译并运行了 进程间文档,用于在共享内存中毫无问题地创建向量。但是,当我修改它以使用 Boostcircular_buffer 时:

int main(int argc, char *argv[])
{
    managed_shared_memory segment(create_only, "MySharedMemory", 65536);
    const ShmemAllocator alloc_inst (segment.get_segment_manager());
    MyCircBuffer  *myCircBuf  = segment.construct<MyCircBuffer>("MyCircBuffer")(alloc_inst);
    return 0;
} 

我收到编译错误(由 segment.construct() 引起)。知道我做错了什么吗?是否因为circular_buffer不是/boost/interprocess/containers中列出的容器之一,即它与Interprocess不兼容?

谢谢,

C

I am trying to create a circular buffer in shared memory using Boost circular_buffer and Interprocess libraries. I compiled and ran the the example given in the Interprocess documentation for creating a vector in shared memory with no problem. However, when I modify it to use the Boost circular_buffer as:

int main(int argc, char *argv[])
{
    managed_shared_memory segment(create_only, "MySharedMemory", 65536);
    const ShmemAllocator alloc_inst (segment.get_segment_manager());
    MyCircBuffer  *myCircBuf  = segment.construct<MyCircBuffer>("MyCircBuffer")(alloc_inst);
    return 0;
} 

I get a compilation error (caused by segment.construct()). Any idea what I am doing wrong? Is it because circular_buffer is not one of the containers listed in /boost/interprocess/containers, i.e. it's not compatible with Interprocess?

Thanks,

C

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2024-08-29 21:13:49

我在 boost 用户论坛上问了同样的问题,建议的解决方案是使用 -DBOOST_CB_DISABLE_DEBUG 或 -DNDEBUG 标志,因为 circular_buffer 依赖于原始指针来进行调试支持。

还有其他建议吗?

I asked the same question on the boost user forum and the solution that was suggested was to use -DBOOST_CB_DISABLE_DEBUG or -DNDEBUG flags, since circular_buffer relies on raw pointers for debug support.

Any other suggestions?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文