ZBLOG

3.1.2.2.10. WriterResourceLimitsQos This QoS Policy states the limits for the matched DataReaders’ resource limited collections based on the maximum number of DataReaders that are going to match with the DataWriter. See WriterResourceLimitsQos. ...

3.1.2.2.10. WriterResourceLimitsQos

WriterResourceLimitsQos 是一种 QoS(服务质量)策略,用于规定与 DataWriter 匹配的 DataReaders 的资源限制集合的限制,具体取决于将要与该 DataWriter 匹配的最大 DataReader 数量。

QoS 策略的数据成员列表:

数据成员名称 类型
matched_subscriber_allocation ResourceLimitedContainerConfig

| reader_filters_allocation | ResourceLimitedContainerConfig |

注意: 此 QoS 策略适用于 DataWriter 实体,并且在启用实体上无法更改。

示例

以下是如何在 C++ 中使用 WriterResourceLimitsQos 的示例:

// 此示例仅适用于 DataWriter 实体
DataWriterQos writer_qos;

// 将匹配订阅者资源限制集合的最大大小设置为 3,并将其分配配置设置为固定大小
writer_qos.writer_resource_limits().matched_subscriber_allocation =
        eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(3u);

// 将写方内容过滤器的最大数量设置为 1,并将其分配配置设置为固定大小
writer_qos.writer_resource_limits().reader_filters_allocation =
        eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(1u);

// 使用修改后的 QoS 创建 DataWriter 实体
writer_ = publisher_->create_datawriter(topic_, writer_qos);

解释

在上述代码中,首先创建一个 DataWriterQos 对象。接着,对几个关键字段进行配置:

  1. matched_subscriber_allocation: 设置与此数据写入器匹配的数据订阅者资源限制集合的最大容量,这里被设定为 3。这意味着最多可以有 3 个数据订阅者同时与这个数据写入器匹配。

  2. reader_filters_allocation: 指定允许使用的读方内容过滤器的最大数量,这里设定为最多可以有 1 个内容过滤器。内容过滤器用于筛选哪些数据可以被特定的数据读取器接收。

最后,通过调用 publisher_->create_datawriter() 方法并传入修改后的 QoS 设置来创建数据写入器实例。这确保了新创建的数据写入器能够根据指定的资源限制和参数正常工作,从而有效管理其所需资源。在这种情况下,它会保证只有有限数量的数据订阅者和过滤器能够被管理,以优化性能和资源使用。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:http://sdn.0voice.com/?id=7839

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?