-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TypeAdapted publishing with large messages. #2443
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,8 +290,8 @@ class Publisher : public PublisherBase | |
{ | ||
// Avoid allocating when not using intra process. | ||
if (!intra_process_is_enabled_) { | ||
// In this case we're not using intra process. | ||
return this->do_inter_process_publish(msg); | ||
this->do_inter_process_publish(msg); | ||
return; | ||
} | ||
// Otherwise we have to allocate memory in a unique_ptr and pass it along. | ||
// As the message is not const, a copy should be made. | ||
|
@@ -318,22 +318,19 @@ class Publisher : public PublisherBase | |
> | ||
publish(std::unique_ptr<T, PublishedTypeDeleter> msg) | ||
{ | ||
// Avoid allocating when not using intra process. | ||
if (!intra_process_is_enabled_) { | ||
// In this case we're not using intra process. | ||
ROSMessageType ros_msg; | ||
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, ros_msg); | ||
return this->do_inter_process_publish(ros_msg); | ||
auto ros_msg_ptr = std::make_unique<ROSMessageType>(); | ||
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, *ros_msg_ptr); | ||
this->do_inter_process_publish(*ros_msg_ptr); | ||
return; | ||
} | ||
|
||
bool inter_process_publish_needed = | ||
get_subscription_count() > get_intra_process_subscription_count(); | ||
|
||
if (inter_process_publish_needed) { | ||
auto ros_msg_ptr = std::make_shared<ROSMessageType>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need a shared_ptr here, better also use a unique_ptr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This one needs to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh you are right, I overlooked that. |
||
// TODO(clalancette): This is unnecessarily doing an additional conversion | ||
// that may have already been done in do_intra_process_publish_and_return_shared(). | ||
// We should just reuse that effort. | ||
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(*msg, *ros_msg_ptr); | ||
this->do_intra_process_publish(std::move(msg)); | ||
this->do_inter_process_publish(*ros_msg_ptr); | ||
|
@@ -368,13 +365,12 @@ class Publisher : public PublisherBase | |
> | ||
publish(const T & msg) | ||
{ | ||
// Avoid double allocating when not using intra process. | ||
if (!intra_process_is_enabled_) { | ||
// Convert to the ROS message equivalent and publish it. | ||
ROSMessageType ros_msg; | ||
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(msg, ros_msg); | ||
// In this case we're not using intra process. | ||
return this->do_inter_process_publish(ros_msg); | ||
auto ros_msg_ptr = std::make_unique<ROSMessageType>(); | ||
rclcpp::TypeAdapter<MessageT>::convert_to_ros_message(msg, *ros_msg_ptr); | ||
this->do_inter_process_publish(*ros_msg_ptr); | ||
return; | ||
} | ||
|
||
// Otherwise we have to allocate memory in a unique_ptr and pass it along. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# A message with a size larger than the default Linux stack size | ||
uint8[10485760] data | ||
uint64 size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not also move the unique_ptr as all other functions do it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because do_inter_process_publish takes a constref, not a unique_ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was more to change the
rclcpp/rclcpp/include/rclcpp/publisher.hpp
Lines 450 to 451 in b007204