Repository navigation
Fix deprecated rcl allocator conversion in allocator_tutorial_pmr - #817
Merged
Merged
Conversation
…orial rclcpp's fallback C++-to-rcl allocator conversion is deprecated because rcl's deallocate does not pass the block size, which std::pmr::memory_resource::deallocate requires. Add a thin polymorphic_allocator subclass whose get_rcl_allocator() stores each block's size in a header, so rcl allocations still go through the custom memory resource and are freed with the correct size. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]>
ahcorde
approved these changes
Oct 12, 2026
Contributor
|
Pulls: #817 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the deprecation warning introduced in ros2/rclcpp#3058:
allocator_tutorial_pmruses a plainstd::pmr::polymorphic_allocator, so rclcpp falls back to its deprecated C++-to-rcl allocator conversion. That conversion is not valid forstd::pmr: rcl'sdeallocatedoes not pass the block size, butstd::pmr::memory_resource::deallocaterequires it (see ros2/rclcpp#3058).This PR adds
PmrAllocator<T>, a thin subclass ofstd::pmr::polymorphic_allocator<T>that providesget_rcl_allocator(). rclcpp uses this function instead of the deprecated fallback. The approach is the same as ros2/realtime_support#139 (TLSF), adapted tostd::pmr:alignof(std::max_align_t)bytes), sodeallocateis called with the real size and alignment.noexceptand returnnullptron failure or size overflow, likemalloc/calloc/realloc.reallocateleaves the original block untouched on failure, andzero_allocatezeroes the memory.Tested on macOS (arm64) against current Rolling rclcpp, running
ros2 run demo_nodes_cpp allocator_tutorial [intra]for about 5 s and stopping it with Ctrl-C:publisher_options.hpp,subscription_options.hpp,message_memory_strategy.hpp)Is this user-facing behavior change?
The demo no longer emits deprecation warnings at build time, and it exits cleanly on Ctrl-C instead of crashing. The tutorial's code listings show
std::pmr::polymorphic_allocator<void>and would need a matching docs update toPmrAllocator<void>.Did you use Generative AI?
Yes. This PR description was AI-generated with Claude Code (Claude Opus 5.5). The
PmrAllocatorcode in this PR was also written with Claude Code (Claude Opus 5.5).Additional Information