# Has a CPU shared-memory backend for rosidl::Buffer been explored?

**URL:** <https://discourse.openrobotics.org/t/has-a-cpu-shared-memory-backend-for-rosidl-buffer-been-explored/57240>\
**Category:** ROS General\
**Tags:** ros2, lyrical\
**Created:** [August 8, 2026, 2:30pm UTC](https://discourse.openrobotics.org/t/has-a-cpu-shared-memory-backend-for-rosidl-buffer-been-explored/57240 "2026-08-08T14:30:45Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Daisuke\_Kato](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/daisuke_kato/32/23487_2.png) [@Daisuke\_Kato](https://discourse.openrobotics.org/u/Daisuke_Kato)\
**Post date:** [August 11, 2026, 1:52pm UTC](https://discourse.openrobotics.org/t/has-a-cpu-shared-memory-backend-for-rosidl-buffer-been-explored/57240/4 "2026-08-11T13:52:47Z")

</div>

While working on this feature, I noticed that pub/sub message delivery time increases roughly in proportion to the buffer size, even though the payload size is expected to remain constant when using specialized buffer backends.

I looked into it a bit and found that `std::vector<uint8_t>(buffer_size)` zero-initializes the entire buffer, effectively calling `memset` for `buffer_size` bytes. Since the buffer does not need to be initialized in this context, I submitted a patch to avoid both the extra memory allocation and the zero-initialization.

> <https://github.com/ros2/rmw_fastrtps/pull/904>
>
> \## Description
> 
> Previously, heap allocation happend for each endpoint with std…::vector\<uint8\_t\>. This introduced extra memset via its constructor.
> 
> For recent ROS 2, where rosidl::Buffer was introduced, sometimes the actual payload size and message size may not match because only buffer descriptors may be sent. In such a case, now \`get\_serialized\_size()\` seems to be unreliable, and hard to pre-allocate the buffer in that path.
> 
> Fixes #903
> 
> \### Is this user-facing behavior change?
> 
> 
> 
> Possibly yes.
> 
> Previously, it is guaranteed that the heap allocation only happens once per endpoint, through externally managed buffer (allocated with \`std::vector\<uint8\_t\>\`). Now the number of allocations depends on combinations of buffer's strategies, and Cdr's usage. So, in small message cases, this patch will introduce an extra overhead of buffer reallocation.
> 
> For rosidl::Buffer usage, this patch will dramatically reduce extra allocation and zero-initialization when only the optimized message paths exist. 
> 
> \### Did you use Generative AI?
> 
> I used CodeX to investigate the cause analysis, and FastBuffer/Cdr behavior.
> 
> \### Additional Information
> 
> This patch is trying to resolve two issues at same time:
> 
> 1. Reducing extra memory allocation when publishing rosidl::Buffer via optimized buf (carries only a descriptor) 
> 2. Removing extra memset caused by \`std::vector\<uint8\_t\>\` constructor.
> 
> What I originally found is the second point, so if we wish more conservative way, it is possible to reserve the \`fast\_buffer\` as previouslly. Still, I believe it is better to reuse that buffer accross endpoints, in my perspective...
> 
> Since this is my first PR to \`rmw\_fastrtps\` repository, let me know if I missed anything.

---

_[View the full topic](https://discourse.openrobotics.org/t/has-a-cpu-shared-memory-backend-for-rosidl-buffer-been-explored/57240)._
