问题描述
尝试实施一个生产者使用的方案,其中一个进程可以提供 cv :: Mat对象放入队列缓冲区.消费者消费它们. cv :: Mat 具有可设置的分配器可以实现自定义内存管理,但是在使它起作用方面没有成功.消费者方的爆破导致了段错误.我最接近的是此实现,其中cv :: Mat已序列化并反序列化了.该实现的另一个缺点是在编译期间定义了缓冲区大小.因此,我们重申以下问题:如何在共享内存中有效地实现cv :: Mat无锁队列.
Trying to implement a produced consumer scenario where one process feeds cv::Mat objects into a queue buffer. And the consumer consumes them. cv::Mat has a settable allocator that can be implemented for custom memory management, but I had no success in making it work. Popping from the que on consumer side led to segfaults. The closest I've got is this implementation whwre cv::Mat is serialized and deserialized. Another downside of this implementation is buffer size is defined during compilation. So to reiterate the questions: how to efficiently implement cv::Mat lockfree queue in a shared memory.
相关问题:
推荐答案
可设置" cv :: Mat
的分配器不是Boost进程间分配器.
The "settable" allocator for cv::Mat
is NOT a Boost Interprocess allocator.
看起来它会变得困难".实施 cv :: Matallocator
接口也要包装一个.
It looks like it's gonna be "hard" to implement the cv::Matallocator
interface to wrap one, as well.
因此,我强烈建议序列化.除非您要处理巨型矩阵,否则这应该没问题.参见例如
So, I'd strongly suggest serializing. This should be okay unless you're dealing with giant matrices. See e.g.
您当然可以序列化到共享内存:https://www.boost.org/doc/libs/1_37_0/doc/html/interprocess/streams.html 或 https://www.boost.org/doc/libs/1_74_0/libs/iostreams/doc/quick_reference.html#devices
Of course you can serialize to shared memory: https://www.boost.org/doc/libs/1_37_0/doc/html/interprocess/streams.html or https://www.boost.org/doc/libs/1_74_0/libs/iostreams/doc/quick_reference.html#devices
现在,如果您需要大型矩阵(无论如何都需要将其用作OpenCV),请考虑使用现有的CV分配器从共享内存中的已经存在的连续缓冲区中进行分配.
Now if you need large matrices (and they NEED to be OpenCV anyways) consider using existing CV allocators to allocate from an already existing contiguous buffer in your shared memory.
这可能只是一个 vector< int8_t,bip :: allocator< int8_t>>
或实际上是 array< int8_t,4096>
构造在共享内存(托管( managed_shared_memory
)或非托管( bip :: mapped_region
可以在 bip :: shared_memory_object
)上运行.
This could be as simple as just a vector<int8_t, bip::allocator<int8_t> >
or, indeed array<int8_t, 4096>
constructed inside shared memory (either managed (managed_shared_memory
) or unmanaged (bip::mapped_region
that works on top of bip::shared_memory_object
).
这篇关于如何使用运行时大小参数构造boost spsc_queue,以使用共享内存在两个进程之间交换cv :: Mat对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!