Ask Your Question

Is it possible to reuse ROS messages?

asked 2014-08-06 15:17:31 -0500

Neil Traft gravatar image

After calling publish, can I reuse the same message object to send a similar message with some small changes? Basically I'm asking if the message is already serialized by the time the publish function returns. If it's not serialized right away, then there is a chance that I could overwrite some values from the previous message, and so it would not be possible to reuse it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-06 15:53:00 -0500

ahendrix gravatar image

In most cases, it's fine to re-use message objects.

if you're publishing shared pointers to messages, and subscribing within the came C++ node (or another nodelet in the same process), the pointers are passed directly, and the message should not be modified after it is published.

edit flag offensive delete link more


Okay, I think I understand the concern when publishing within the same node (because the message is never serialized), but if the message is serialized then it is done synchronously and is finished by the time `publish` returns?

Neil Traft gravatar image Neil Traft  ( 2014-08-06 16:25:20 -0500 )edit

Okay, I see it now. I just didn't know how to dig into the source code before, but I can see now that in topic_manager.cpp it is serialized right away.

Neil Traft gravatar image Neil Traft  ( 2014-08-06 16:30:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-06 15:17:31 -0500

Seen: 359 times

Last updated: Aug 06 '14