ROS2 supports intra-process communication when composing multiple nodes in a single process. It additionally can avoid doing any copies of the data when published using std::unique_ptr<MessageT> and subscribed using shared_ptr<const MessageT> or std::unique_ptr<MessageT> (at most 1 subscriber)
This PR is my attempt to add support for publishing using std::unique_ptr without breaking any of the existing APIs.
The idea is that:
Each publisher plugin can decide whether they support publishing using unique ptr (for now I don't see how any other plugin than raw can take advantage of the ownership).
The new Publisher::publish(sensor_msgs::msg::Image::UniquePtr message) method first publishes using the const reference to plugins that don't support std::unique_ptr, then moves the ownership of the message to (at most 1) plugin that supports it.
If there is more than one plugin that supports std::unique_ptr and has subscriptions, we pass the ownership to only one such plugin (the first we find), and for the rest we still use const reference, delegating doing any extra copies to plugin implementations.
Related issues/prs:
212
215
216 (kinda)This is an automatic backport of pull request #306 done by Mergify.
ROS2 supports intra-process communication when composing multiple nodes in a single process. It additionally can avoid doing any copies of the data when published using
std::unique_ptr<MessageT>
and subscribed usingshared_ptr<const MessageT>
orstd::unique_ptr<MessageT>
(at most 1 subscriber)This PR is my attempt to add support for publishing using
std::unique_ptr
without breaking any of the existing APIs.The idea is that:
raw
can take advantage of the ownership).Publisher::publish(sensor_msgs::msg::Image::UniquePtr message)
method first publishes using the const reference to plugins that don't supportstd::unique_ptr
, then moves the ownership of the message to (at most 1) plugin that supports it.std::unique_ptr
and has subscriptions, we pass the ownership to only one such plugin (the first we find), and for the rest we still use const reference, delegating doing any extra copies to plugin implementations.Related issues/prs:
212
215
216 (kinda)
This is an automatic backport of pull request #306 done by Mergify.