Skip to content

Conversation

@Yuchen966
Copy link

Description

Updates the intra-process communication design document to reflect the actual current behavior with respect to function publish():
shared_ptr messages: Cannot be published (removed incorrect zero-copy claims)
unique_ptr messages: Zero-copy transfer achieved
raw messages: Both msg and std::move(msg) result in copying
Key changes:

  • Add notes about current behaviour
  • Removed the entire "Publishing SharedPtr" table section since shared_ptr cannot be published

Fixes # (issue)

Is this user-facing behavior change?

No

Did you use Generative AI?

No

Additional Information

| unique_ptr\<MsgT\> @1 | unique_ptr\<MsgT\> <br> unique_ptr\<MsgT\> | @1 <br> @2 |
| unique_ptr\<MsgT\> @1 | shared_ptr\<MsgT\> | @1 |
| unique_ptr\<MsgT\> @1 | shared_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @1 |
| unique_ptr\<MsgT\> @1 | shared_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @2 |
Copy link
Contributor

@alsora alsora Nov 16, 2025

Choose a reason for hiding this comment

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

your change here is wrong
if there is 1 publisher with unique ptr and two subscribers with shared pointers, both receive the same publisher pointer (@1 in this case)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your suggestions. I just took a deeper look into the code, and I noticed that only shared_ptr<const MsgT> would share the stored object pointer and avoid extra copy. Every sharedptr containing non-const msg would require intra process manager do another copy. The changes I made is based on my experiments on shared_ptr<MsgT>, which is non-const.

I think the current implementation makes sense, as non-const sharedptr could be changed and an extra copy is necessary for safety reasons. But the table doesn't show the constness of MsgT. It also seems weird that the first part of design documentation specifies const MsgT, but at some point this gets lost. I will update the document to emphasize the constness of shared_ptr.

| unique_ptr\<MsgT\> @1 | shared_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @1 |
| unique_ptr\<MsgT\> @1 | shared_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @2 |
| unique_ptr\<MsgT\> @1 | unique_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @2 |
| unique_ptr\<MsgT\> @1 | unique_ptr\<MsgT\> <br> shared_ptr\<MsgT\> <br> shared_ptr\<MsgT\> | @1 <br> @2 <br> @2|
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think these should be removed

Copy link
Contributor

@alsora alsora left a comment

Choose a reason for hiding this comment

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

shared_ptr messages: Cannot be published (removed incorrect zero-copy claims)

Shared pointers CAN be published, although they don't achieve zero copy.
This is exactly what's indicated in the #### Publishing SharedPtr section that you removed.

My bad, i forgot that publishing shared_ptr has been deprecated long ago.

However, your PR is also making incorrect changes.

I think we should just remove the section about Publishing shared_ptr.

The following tables show a recap of when the proposed implementation has to create a new copy of a message.
The notation `@` indicates a memory address where the message is stored, different memory addresses correspond to different copies of the message.

**Note on current behavior**: The actual implementation behavior differs from the proposed implementation as described in [rclcpp issue #2872](https://github.com/ros2/rclcpp/issues/2872):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this section.
The fact that you can't publish shared ptr is not necessarily related to this design.

Moreover, i don't really see many references to publishing shared ptrs in this page.

these should be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rclcpp does not support zero-copy intra-process communication for shared_ptr or std::move raw messages

2 participants