Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion source/Tutorials/Demos/Intra-Process-Communication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ In this case, since they only come once per second, usually only the first messa
Finally, you can see that "Published message..." and "Received message ..." lines with the same value also have the same address.
This shows that the address of the message being received is the same as the one that was published and that it is not a copy.
This is because we're publishing and subscribing with ``std::unique_ptr``\ s which allow ownership of a message to be moved around the system safely.
You can also publish and subscribe with ``const &`` and ``std::shared_ptr``, but zero-copy will not occur in that case.
You can also subscribe using a ``const std::shared_ptr<const T> &`` (``ConstSharedPtr``) callback, which shares immutable ownership of the message and achieves zero-copy even with multiple subscribers.
Comment thread
MShields1986 marked this conversation as resolved.
Outdated
Comment thread
MShields1986 marked this conversation as resolved.
Outdated
Subscribing with a plain ``const T &`` or a mutable ``std::shared_ptr<T>`` will not achieve zero-copy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if you still see this with a newer version of rclcpp (Lyrical/Rolling). IIRC, const T & should now have the same effect as const std::shared_ptr<const T> or std::shared_ptr<const T>.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see exactly what I tested in more detail here. I could add cases but would be good to get a full matrix of what anyone wants to see first.

Might be scope creep for this specific PR though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coincidentally, I actually wrote a similar Discourse post at the beginning of this year documenting these behaviors (though mine is not as comprehensive as yours). That post eventually led to a PR fixing the const T & case, so I think this sentence may no longer be accurate.

My two cents would be to validate it and update the sentence if needed, or simply remove it since the tutorial doesn't mention it anyway.


The cyclic pipeline demo
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -377,6 +378,12 @@ It can be, however, delivered to one of them.
Which one would get the original pointer is not defined, but instead is simply the last to be delivered.
And so one of the images being viewed is the original, with all the pointers the same, and the other is a copy of the original image, made between the ``watermark_node`` and one of the ``image_view_node`` instances, which will have a different pointer for the third line of text.

To avoid this copy in a one-to-many pipeline, subscribers can use ``ConstSharedPtr``
(i.e. ``const std::shared_ptr<const T> &``) callbacks instead of ``UniquePtr``.
The publisher retains a single immutable shared object and delivers it to all intra-process
subscribers without copying, at the cost of no longer being able to mutate the message after
publishing.
Comment thread
MShields1986 marked this conversation as resolved.
Outdated

Pipeline with inter-process viewer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down