ZBLOG

3.1.2.2.9. ReaderResourceLimitsQos This QoS Policy states the limits for the matched DataWriters’ resource limited collections based on the maximum number of DataWriters that are going to match with the DataReader. See ReaderResourceLimitsQos. L...

3.1.2.2.9. ReaderResourceLimitsQos

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

QoS 策略的数据成员列表:

数据成员名称 类型
matched_publisher_allocation ResourceLimitedContainerConfig

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

示例

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

// 此示例仅适用于 DataReader 实体
DataReaderQos reader_qos;

// 将匹配发布者资源限制集合的最大大小设置为 1,并将其分配配置设置为固定大小
reader_qos.reader_resource_limits().matched_publisher_allocation =
        eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(1u);

// 将样本信息资源限制的最大大小设置为 22,并将其分配配置设置为固定大小
reader_qos.reader_resource_limits().sample_infos_allocation =
        eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(22u);

// 将匹配发布者资源限制集合的最大大小设置为 3,并将其分配配置设置为固定大小
reader_qos.reader_resource_limits().outstanding_reads_allocation =
        eprosima::fastdds::ResourceLimitedContainerConfig::fixed_size_configuration(3u);

// 设置每次读取的最大样本数
reader_qos.reader_resource_limits().max_samples_per_read = 42;

// 使用修改后的 QoS 创建 DataReader 实体
reader_ = subscriber_->create_datareader(topic_, reader_qos);

解释

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

  1. matched_publisher_allocation: 设置与此数据阅读器匹配的数据发布者资源限制集合的最大容量,这里被设定为 1。

  2. sample_infos_allocation: 配置样本信息(即关于已接收数据的信息)的资源限制,此处设定为最多可以存储 22 个样本信息。

  3. outstanding_reads_allocation: 指定未完成读取操作的最大数量,这里设定为最多可以有 3 个未完成读取。

  4. max_samples_per_read: 每次读取操作允许获取的最大样本数量,此处设定为 42。

最后,通过调用 subscriber_->create_datareader() 方法并传入修改后的 QoS 设置来创建数据读取器实例。这确保了新创建的数据读取器能够根据指定的资源限制和参数正常工作,从而有效管理其所需资源。


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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?