When a DDS sample is written, the DataWriter serializes it and stores the result in a buffer obtained from a pool of preallocated buffers. In the same way, when a DDS sample is received, the DataReader deserializes it and stores the result in a DDS sample coming from a pool of preallocated DDS samples.
By default, the buffers on the DataWriter and the samples on the DataReader are preallocated with their maximum size. For example:
struct MyString Unknown macro: { string<128> value; }
This IDL-defined type has a maximum serialized size of 133 bytes (4 bytes for length + 128 characters + 1 NULL terminating character). So the serialization buffers will have a size of 133 bytes. The buffer can hold samples with 128 characters strings. Consequently, the preallocated samples will be sized to keep this length.
However, for built-in types, the maximum size of the buffers/DDS samples is unknown and depends on the nature of the application using the built-in type.
For example, a video surveillance application that is using the keyed octets built-in type to publish a stream of images will require bigger buffers than a market-data application that uses the same built-in type to publish market-data values.
To accommodate both kinds of applications and optimize memory usage, you can configure the maximum size of the built-in types on a per-DataWriter or per-Datareader basis using the PROPERTY QosPolicy (DDS Extension) . lists the supported built-in type properties. When the properties are defined in the DomainParticipant, they are applicable to all DataWriters and DataReaders belonging to the DomainParticipant, unless they are overwritten in the DataWriters and DataReaders.
These properties must be set consistently with respect to the corresponding *.max_size properties in the DomainParticipant (see ). The value of the alloc_size property must be less than or equal to the max_size property with the same name prefix in the DomainParticipant.
Examples—Setting the Maximum Size for a String Programmatically includes examples of how to set the maximum size of a string built-in type for a DataWriter programmatically, for each API. You can also set the maximum size of the built-in types using XML QoS Profiles. For example, the following XML shows how to set the maximum size of a string built-in type for a DataWriter.
<dds> <qos_library name="BuiltinExampleLibrary"> <qos_profile name="BuiltinExampleProfile"> <datawriter_qos> <property> <value> <element> <name>dds.builtin_type.string.alloc_size</name> <value>2048</value> </element> </value> </property> </datawriter_qos> <datareader_qos> <property> <value> <element> <name>dds.builtin_type.string.alloc_size</name> <value>2048</value> </element> </value> </property> </datareader_qos> </qos_profile> </qos_library> </dds>
For simplicity, error handling is not shown in the following examples.
DDS_DataWriter * writer = NULL; DDS_StringDataWriter * stringWriter = NULL; DDS_Publisher * publisher = ... ; DDS_Topic * stringTopic = ... ; struct DDS_DataWriterQos writerQos = DDS_DataWriterQos_INITIALIZER; DDS_ReturnCode_t retCode; retCode = DDS_DomainParticipant_get_default_datawriter_qos (
participant, &writerQos); retCode = DDS_PropertyQosPolicyHelper_add_property ( &writerQos.property, "dds.builtin_type.string.alloc_size", "1000",
DDS_BOOLEAN_FALSE); writer = DDS_Publisher_create_datawriter(
publisher, stringTopic, &writerQos,
NULL, DDS_STATUS_MASK_NONE); stringWriter = DDS_StringDataWriter_narrow(writer); DDS_DataWriterQos_finalize(&writerQos);
#include "ndds/ndds_namespace_cpp.h" using namespace DDS; ... Publisher * publisher = ... ; Topic * stringTopic = ... ; DataWriterQos writerQos; ReturnCode_t retCode = participant->get_default_datawriter_qos(writerQos); retCode = PropertyQosPolicyHelper::add_property (
&writerQos.property, "dds.builtin_type.string.alloc_size", "1000", BOOLEAN_FALSE); DataWriter * writer = publisher->create_datawriter( stringTopic, writerQos, NULL, STATUS_MASK_NONE); StringDataWriter * stringWriter = StringDataWriter::narrow(writer);
dds::pub::qos::DataWriterQos writer_qos = participant.default_datawriter_qos(); writer_qos.policy<rti::core::policy::Property>().set({ "dds.builtin_type.string.alloc_size", "1000"}); dds::pub::DataWriter<dds::core::StringTopicType> writer( publisher, string_topic, writer_qos);
using namespace DDS; ... Topic^ stringTopic = ... ; Publisher^ publisher = ... ; DataWriterQos^ writerQos = gcnew DataWriterQos(); participant->get_default_datawriter_qos(writerQos); PropertyQosPolicyHelper::add_property( writerQos->property_qos, "dds.builtin_type.string.alloc_size", "1000", false); DataWriter^ writer = publisher->create_datawriter( stringTopic, writerQos, nullptr, StatusMask::STATUS_MASK_NONE); StringDataWriter^ stringWriter = safe_cast<StringDataWriter^>(writer);
using DDS; ... Topic stringTopic = ... ; Publisher publisher = ... ; DataWriterQos writerQos = new DataWriterQos(); participant.get_default_datawriter_qos(writerQos); PropertyQosPolicyHelper.add_property ( writerQos.property_qos, "dds.builtin_type.string.alloc_size", "1000", false); StringDataWriter stringWriter = (StringDataWriter) publisher.create_datawriter( stringTopic, writerQos, null, StatusMask.STATUS_MASK_NONE);
import com.rti.dds.publication.*; import com.rti.dds.type.builtin.*; import com.rti.dds.infrastructure.*; ... Topic stringTopic = ... ; Publisher publisher = ... ; DataWriterQos writerQos = new DataWriterQos(); participant.get_default_datawriter_qos(writerQos); PropertyQosPolicyHelper.add_property ( writerQos.property, "dds.builtin_type.string.alloc_size", "1000", false); StringDataWriter stringWriter =
(StringDataWriter) publisher.create_datawriter( stringTopic, writerQos, null, StatusKind.STATUS_MASK_NONE);
In some scenarios, the maximum size of a built-in type is not known in advance and there is no a reasonable maximum size. For example, this could occur in a file transfer application using the built-in type Octets. Setting a large value for the dds.builtin_type.*.alloc_size property would involve high memory usage.
For the above use case, you can configure the built-in type to be unbounded by setting the property dds.builtin_type.*.alloc_size to the maximum value of a 32-bit signed integer: 2,147,483,647. Then the middleware will not preallocate the DataReader queue's samples to their maximum size. Instead, it will deserialize incoming samples by dynamically allocating and deallocating memory to accommodate the actual size of the sample value.
To configure unbounded support for built-in types:
See these sections in the RTI Connext DDS Core Libraries User's Manual:
Unbounded built-in types are only supported in the C, C++, .NET, and Java APIs.
© 2016 RTI