pre-allocated message buffers and zero-copy publishing

asked 2022-03-08 10:27:48 -0600

fhwedel-hoe gravatar image

updated 2022-03-08 10:31:38 -0600

Hi all

I am trying to implement real zero-copy publishing in a camera driver for ros2 foxy. I succeeded in adapting the tutorial Efficient Intra Process Communication to sensor_msgs::msg::Image and publishing with std::unique_ptr.

However, there is a challenge: For efficiency, the camera expects a buffer to be pre-allocated in the application. The buffers cannot be changed while the camera is running. This means I somehow need an approach where I can write to a sensor_msgs::msg::Image's data and publish it. But the unique_ptr's deleter must never invalidate the buffer. Even after the unique_ptr was std::moved out of the publisher's scope. My approach of wrapping a raw pointer in a unique_ptr can work once per allocated buffer.

I suspected I just was not competent enough in the C++ department and asked for help over at stackoverflow. So far, I have not received any helpful answers. Maybe the problem is too deep in the ROS context. Remy Lebau's comment seems to suggest, what I want is not possible with the current interfaces.

Is there anything else I can try for sharing image data across nodes on the same system? I want to keep it compatible with the existing pipelines, so custom messages are not an option.

Kind Regards

edit retag flag offensive close merge delete