How to implement a circular buffer of cv::Mat objects (OpenCV)?

笑着哭i 提交于 2019-11-29 11:28:20

Whats wrong with just a vector and an index to the next slot to write to and the next one to process?

All you have to handle is the wrap around when you get to the end, and if you use a power of 2 in the vector size you can use a simple mask for that.

A circular buffer is thread-safe when only the writing thread updates the end pointer and only the reading thread updates the start pointer, and accesses to those pointers are atomic. You have a spot in cbWrite that updates start which will lead to a race condition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!