Repository navigation
Allocator tutorial: provide get_rcl_allocator() for the pmr allocator - #7296
Conversation
rclcpp falls back to a deprecated C++-to-rcl allocator conversion when the allocator has no get_rcl_allocator() member; that conversion passes a wrong size to deallocate (see ros2/rclcpp#3058). Explain why rcl needs its own allocator, show a std::pmr::polymorphic_allocator wrapper that provides one by storing the block size in a header, and use it in the example main. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]>
Replace the elided allocate/deallocate bodies with the complete code from demo_nodes_cpp's allocator_tutorial_pmr.cpp, including reallocate_block, zero_allocate_block and the required includes, and drop the note about the fallback conversion. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]>
75d4866 to
9c6683c
Compare
|
@3di-for-openrobotics @keithkirkwood-3di @kacperbojakowski-3di @sarahfarnborough-3di sorry, gotta need to ask some help here. #6981 really make it difficult to complete the action and merge the PR. it does not really tell what went wrong and how to fix though, can you have a look? |
@fujitatomoya Hi! Yes, the solution causes PRs to fail, here is a hotfix to address that: #7294 |
…al-get-rcl-allocator Signed-off-by: Maurice <[email protected]>
kscottz
left a comment
There was a problem hiding this comment.
@mini-1235 appreciate the help! This is really helpful content but the grammar and code need some work to make this complex topic a bit more accessible to the reader.
I made some inline suggestions, but an easier solution would be to just pipe the change through an LLM to tighten up the language and add comments to most of the code.
Co-authored-by: Katherine Scott <[email protected]> Signed-off-by: Maurice Alexander Purnawan <[email protected]>
Signed-off-by: Maurice <[email protected]>
kscottz
left a comment
There was a problem hiding this comment.
Certainly better than the initial version.
This is relevant to this PR but this particular is getting pretty long. We may want to consider breaking it up in the future.
Thanks for the help! This is the kind of content that can really help users.
…#7296) (#7456) * Allocator tutorial: provide get_rcl_allocator() for the pmr allocator rclcpp falls back to a deprecated C++-to-rcl allocator conversion when the allocator has no get_rcl_allocator() member; that conversion passes a wrong size to deallocate (see ros2/rclcpp#3058). Explain why rcl needs its own allocator, show a std::pmr::polymorphic_allocator wrapper that provides one by storing the block size in a header, and use it in the example main. * Allocator tutorial: show the full PmrAllocator implementation Replace the elided allocate/deallocate bodies with the complete code from demo_nodes_cpp's allocator_tutorial_pmr.cpp, including reallocate_block, zero_allocate_block and the required includes, and drop the note about the fallback conversion. * Apply batched suggestions from code review * Clarify allocator tutorial code and fix sentence lint --------- (cherry picked from commit 2108c88) Signed-off-by: Maurice <[email protected]> Signed-off-by: Maurice Alexander Purnawan <[email protected]> Co-authored-by: Maurice Alexander Purnawan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Katherine Scott <[email protected]> Co-authored-by: Tomoya Fujita <[email protected]>
Description
Updates the Allocator Template Tutorial to match the pmr demo in ros2/demos (
demo_nodes_cpp/src/topics/allocator_tutorial_pmr.cpp), which now gives its allocator aget_rcl_allocator()member.Without that member, rclcpp falls back to a generic C++-to-rcl allocator conversion that passes a wrong size to
deallocate(see ros2/rclcpp#3058). That fallback is deprecated, so the tutorial's code produced this warning when built against current Rolling:The same warning is raised from
subscription_options.hppandmessage_memory_strategy.hpp.rcl_allocator_tto send those allocations to the custom allocator too. The section explains why the callbacks cannot just forward to the C++ allocator: rcl'sdeallocatedoes not pass the block size, butstd::pmr::memory_resource::deallocateneeds it.PmrAllocatorimplementation from the demo: a thin subclass ofstd::pmr::polymorphic_allocatorwhoseget_rcl_allocator()stores each block's size in a header in front of it. The callbacks arenoexceptand returnnullptron failure, likemalloc.Allocalias fromstd::pmr::polymorphic_allocator<void>toPmrAllocator<void>.Fixes # (issue)
Did you use Generative AI?
Yes. This PR description was AI-generated with Claude Code (Claude Opus 5.5), and Claude Code (Claude Opus 5.5) also helped write the documentation changes.
Additional Information
Companion change in ros2/demos: ros2/demos#817
Checked locally with the repository's CI targets:
make test(doc8),make lint(sphinx-lint),make spellcheck(codespell) andmake html(Sphinx with warnings treated as errors).🤖 Generated with Claude Code