Skip to content
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

TypeAdapted publishing doesn't use provided allocator #2477

Open
thomasmoore-torc opened this issue Apr 2, 2024 · 3 comments
Open

TypeAdapted publishing doesn't use provided allocator #2477

thomasmoore-torc opened this issue Apr 2, 2024 · 3 comments
Assignees

Comments

@thomasmoore-torc
Copy link

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • From source
  • Version or commit hash:
  • DDS implementation:
    • Fast-RTPS, RTI Connext
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

Create a publisher using an adapted type and a custom allocator

using AdaptedType = rclcpp::adapt_type<std::string>::as<std_msgs::msg::String>;

auto alloc = std::make_shared<MyAllocator<void>>();
rclcpp::PublisherOptionsWithAllocator<MyAllocator<void>> publisher_options;
publisher_options.allocator = alloc;
auto publisher = node->create_publisher<AdaptedType>(
  "allocator_tutorial", 10, publisher_options);

publisher->publish("A string");

Expected behavior

The ROS message that is created by Publisher::publish() will be allocated using the provided allocator.

Actual behavior

The ROS message is allocated using std::make_unique<ROSMessageType>()

Additional information

Rather than using std::make_unique<ROSMessageType>(), the create_ros_message_unique_ptr() can be used instead in the following two locations:

-       auto ros_msg_ptr = std::make_unique<ROSMessageType>();
+       auto ros_msg_ptr = create_ros_message_unique_ptr();
@fujitatomoya
Copy link
Collaborator

@thomasmoore-torc thank you for creating the issue and suggested fix, see #2478

@thomasmoore-torc
Copy link
Author

@fujitatomoya - I noticed that the Windows build had some test failures, and while looking into that, I noticed that there were some similar issues to this introduced as part of #2303. Would it make sense to incorporate the following changes as part of this issue?

-       auto ros_msg_ptr = std::make_shared<ROSMessageType>();
+       auto ros_msg_ptr = std::allocate_shared<ROSMessageType, ROSMessageTypeAllocator>(ros_message_type_allocator_);

@fujitatomoya
Copy link
Collaborator

@thomasmoore-torc thanks for checking this. i was aware of windows failure. will try to patch it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants