Support zero-copy intra-process publishing (backport #306) #310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.