Implement shared memory data publishing between nodelets [closed]
I have a set of 3 nodelets running which publish and subscribe to topics amongst themselves. To optimize the process I want to use the shared memory functionality for zero-copy data being shared between nodelets through publish and subscribe. I tried following this example. The example uses a very basic data type for std_msgs::String::ConstPtr
. I am using a custom defined message and I get a compile time error saying that I cannot assign values to boost::shared_ptr.
For e.g. if my message type is the following (MyMessage.msg)-
Header header
int dataA
string dataB
In my publish method I do something like this -
void publishTopic()
{
std::string str("my message");
MyMessage::ConstPtr msg;
msg->dataA = 5;
msg->dataB = str;
myPublisher.publish(msg);
}
Lines msg->dataA = 5
and msg->dataB = str
are giving me the errors. I know I'm doing something wrong with how I'm assigning values to pointers, but cannot think of a solution off the top of my head. Any help will be appreciated.
Can you please also refer a documentation for using boost::shared_ptr in ROS if any exists?