配置零副本借出消息
有关借出消息如何工作的详细信息,请参阅 Loaned Messages 文章。
如何禁用借出消息
发布者
默认情况下,如果底层中间件支持 Loaned Messages,则 Loaned Messages 将尝试从底层中间件借用内存。
ROS_DISABLE_LOANED_MESSAGES
环境变量可用于禁用 Loaned Messages,并恢复到正常的发布者行为,而无需任何代码更改或中间件配置。
您可以使用以下命令设置环境变量:
export ROS_DISABLE_LOANED_MESSAGES=1
To maintain this setting between shell sessions, you can add the command to your shell startup script:
echo "export ROS_DISABLE_LOANED_MESSAGES=1" >> ~/.bashrc
export ROS_DISABLE_LOANED_MESSAGES=1
To maintain this setting between shell sessions, you can add the command to your shell startup script:
echo "export ROS_DISABLE_LOANED_MESSAGES=1" >> ~/.bash_profile
set ROS_DISABLE_LOANED_MESSAGES=1
If you want to make this permanent between shell sessions, also run:
setx ROS_DISABLE_LOANED_MESSAGES 1
订阅
目前在订阅中使用 Loaned Messages 并不安全,请参阅 此问题 中的更多详细信息。
因此,默认情况下,Loaned Messages 在订阅时处于 禁用'' 状态,方法是 `默认将禁用贷款设置为开启 <https://github.com/ros2/rcl/pull/1110>`_ 即使底层中间件支持这一点。
要在订阅时启用 *Loaned Messages*,您需要将环境变量 ``ROS_DISABLE_LOANED_MESSAGES
明确设置为 0
。
export ROS_DISABLE_LOANED_MESSAGES=0
要在 shell 会话之间维护此设置,您可以将命令添加到 shell 启动脚本中:
echo "export ROS_DISABLE_LOANED_MESSAGES=0" >> ~/.bashrc
export ROS_DISABLE_LOANED_MESSAGES=0
要在 shell 会话之间维护此设置,您可以将命令添加到 shell 启动脚本中:
echo "export ROS_DISABLE_LOANED_MESSAGES=0" >> ~/.bash_profile
set ROS_DISABLE_LOANED_MESSAGES=0
如果想要使其在 shell 会话之间永久存在,还可以运行:
setx ROS_DISABLE_LOANED_MESSAGES 0