ros2 / ros2/rclcpp

TypeAdapted publishing doesn't use provided allocator

Open
#2,477 3 comments 0 reactions 2 assignees View on GitHub

@clalancette is already working on this.

Since Apr 18, 2024.

Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

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();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.