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

Is it possible to do *ros_msg?

asked 2012-09-12 10:43:17 -0500

Ammar gravatar image

Hi Community, I am working on a project that involves me defining various ROS msgs most of which are nested with other msgs that I have defined. Anyhow my question is regarding passing these ROS msgs within functions. I create a Ptr to a message, fill in values in it and then push it on a list. Since I create a Ptr to a ros_msg, in order to push it to a list I use *ros_msg, similar to any C++ data structure. I was wondering if this is correct, since it compiles without any errors. Thanks Ammar

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-09-12 11:19:58 -0500

jdlangs gravatar image

I think the better practice would just be to store the pointers themselves. Pushing *msg onto a list will create a (maybe unnecessary) copy of the entire message, whereas copying just the pointer object is cheap. It's also memory-safe because they are shared pointers and there is therefore no worry about the object being deleted or needing an "owner" to free the memory at the end.

Then to access any message data members, just use the standard c++ -> syntax (ptr->member) in place of (*ptr).member

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-09-12 10:43:17 -0500

Seen: 207 times

Last updated: Sep 12 '12