Why is ROS2 Tutorials using SharedPtr for subscriber callbacks?

asked 2021-08-24 07:20:15 -0500

fnax8902 gravatar image

Hello, when following the tutorial at https://docs.ros.org/en/foxy/Tutorial... I realized that void topic_callback(const std_msgs::msg::String::SharedPtr msg) always takes the SharedPtr of the message as an argument. Why isn't it common to just take the message as an argument for the callback, this would look like this void topic_callback(const std_msgs::msg::String msg)? When thinking about it I guess the difference is that one is call by reference and the other one call by value. Is using SharedPtr increasing memory efficiency? Thanks.

edit retag flag offensive close merge delete

Comments

This reads like a duplicate of #q363135.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-24 07:31:02 -0500 )edit