Make ROS2 use zero-copy [closed]
Hello, I would want an intra-process communication without copying of messages. Does it work by default?
For now, the publisher code is:
auto message = make_unique<std_msgs::msg::String>();
message.get()->data = someString;
cout << "INPUT " << (void*)&(message.get()->data) << "\n";
native.get()->publish(message);
which calls publish(std::unique_ptr<MessageT, MessageDeleter> & msg)
.
The subscriber code is:
...subscriberMethod(const std_msgs::msg::String::UniquePtr message) {
cout << "OUTPUT " << (void*)&message.get()->data << "\n";
string text = message.get()->data.c_str();
...
}
This subscriber method is directly registered with create_subscription
. I get an output like
INPUT 0x7fab70000b60
OUTPUT 0x7fab64000b60
that is, there is some copying in between, even if both the publisher and the subscriber are within the same process. I tried the above with shared_ptr
, but the addresses were also different.