A DataReader is attached to exactly one Subscriber that acts as a factory. Additionally, each DataReader is bound to a single Topic since its creation. This Topic must exist prior to the creation of the DataReader, and must be bound to the data type that the DataReader wants to receive.

The effect of creating a new DataReader in a Subscriber for a specific Topic is to initiate a new subscription with the name and data type described by the Topic.

Once the DataReader is created, the application will be informed when changes in the data value are received from remote or local publications. These changes can then be retrieved using the TypedDataReader::take_next_sample member functions of the DataReader.

Safe DDS Usage

In Safe DDS, the DataReader read operations shall be done through a TypedDataReader methods. Refer to Using the TypedDataReader for more information.


DatareaderQos controls the behavior of the DataReader. Internally it contains the following Policy objects:

Safe DDS Usage

Check Memory management to understand how memory is managed in Safe DDS.


// Construct DataReaderQos with default values
DataReaderQos datareader_qos{};

// Set DurabilityQosPolicy
datareader_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_DURABILITY_QOS;

// Set DeadlineQosPolicy
datareader_qos.deadline().period = {1, 0};

// Set LivelinessQosPolicy
datareader_qos.liveliness().kind = LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS;
datareader_qos.liveliness().lease_duration = {1, 0};

// Set ReliabilityQosPolicy
datareader_qos.reliability().kind = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS;

// Set HistoryQosPolicy
datareader_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
datareader_qos.history().depth = 10;

// Set ResourceLimitsQosPolicy
datareader_qos.resource_limits().max_instances = 10;
datareader_qos.resource_limits().max_samples_per_instance = 3;
datareader_qos.resource_limits().max_samples = 1000;

// Set wire protocol configuration
datareader_qos.wire_protocol_qos().output_integrity = protocol::OutputIntegrityCheck::ENABLED;

// Set DataReaderAllocationsQosPolicy memory configuration
datareader_qos.allocations().preallocated_instances = 10;