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

Revision history [back]

click to hide/show revision 1
initial version

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