How large are Subscriber/Publisher/ServiceServer instances?

asked 2020-01-29 09:49:26 -0500

joaocandre gravatar image

I'm writing a wrapper class that advertises several topics and services, and I'm unsure if I should store ros::Subscriber/ros::Publisher/ros::ServiceServer members by value of by reference/on a vector. Is there a rule of thumb/general practice regarding these kind of situations?

edit retag flag offensive close merge delete

Comments

1

Generally speaking for any non-trivial object you should store a reference or a pointer to it but the actual answer would be predicated on your application. You really haven't provided enough details to make a call one way or the other. I would encourage you to look at the source files to confirm that you won't have any issues.

kscottz gravatar image kscottz  ( 2020-01-29 13:24:08 -0500 )edit

Unless you construct it in the vector itself so you're not copying around.

In general though if you have some stuff you want in a vector for this case, a pointer makes sense. A reference only if the object is still being kept in scope.

stevemacenski gravatar image stevemacenski  ( 2020-01-29 16:48:47 -0500 )edit