ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

What is the difference between nodes that publishes/subscribes to a ConstPtr and a nodelet that publishes/subscribes to a Const::Ptr?

asked 2020-03-27 09:53:21 -0500

Roozter gravatar image

My understanding is that nodelet's don't make an extra copy of data and therefore are more efficient, However if I am sending a ConstPtr between nodes I shouldn't generate an extra copy of the data the ptr points to as well correct?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-27 10:31:24 -0500

gvdhoorn gravatar image

updated 2020-03-27 10:32:10 -0500

However if I am sending a ConstPtr between nodes I shouldn't generate an extra copy of the data the ptr points to as well correct?

If you're asking whether publishing a ConstPtr allows nodes to also benefit from zero-copy message exchange, then no, that's (unfortunately) not how it works.

nodelets can exchange messages without copying anything as they share the same memory address space. This allows them to (essentially) exchange pointers to messages, instead of (copies of) the messages themselves.

Nodes are run in separate processes, each with their own memory address space. Exchanging pointers would be meaningless, as objects will not "live" at the same addresses for these different processes.

So even though you're publish(..)ing a ConstPtr, the middleware will have to make a copy, as there is no other way to reliably exchange message data between nodes (ie: processes).

See #q346374 for another recent question about this.

edit flag offensive delete link more

Comments

Thanks! I didn't know each process would have its own memory address space.

Roozter gravatar image Roozter  ( 2020-03-27 10:49:59 -0500 )edit
1

It's one of the techniques used in process isolation.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-27 11:07:47 -0500 )edit
1

And for future readers: yes, shared memory could be used, and has been in the past. See ethzasl_message_transport and shm_transport for example (just two examples).

These have a nr of disadvantages. Just three would be:

  1. they're not part of the main distribution, and maintenance depends on community contributions, leading to these plugins/extensions falling behind/becoming unmaintained
  2. because they are not integrated completely, code changes are required to use them, leading to tight coupling between nodes and transports
  3. exchanging pointers over shared memory immediately means publishers have to adhere to an (implied) contract, and so do subscribers. For instance: subscribers must not change messages as changes will automatically be visible to all other subscribers (use of ConstPtr definitely helps here)
gvdhoorn gravatar image gvdhoorn  ( 2020-03-27 11:28:08 -0500 )edit

Question Tools

Stats

Asked: 2020-03-27 09:53:21 -0500

Seen: 232 times

Last updated: Mar 27 '20