HOWTO Reduce Bandwidth by Reordering Fields of Your Type

RTI Connext DDS uses the CDR standard to serialize data into the form that is sent over the network.  

The CDR specifies that the fields of your data type are aligned on their natural boundaries.  This means that a primitive that is N octets in length must start at a memory location that is a multiple of N past the beginning of your serialized stream.  Because of this, padding may be added between fields to ensure that a field starts at the expected offset.  In most cases this padding is small in comparison to the size of your data, but if you are looking to conserve bandwidth you can get incrementally smaller bandwidth usage by reordering the fields in your data.

You can optimize the serialized size of your data type by:

  • Positioning fields with larger data types at the beginning of your data
  • Grouping same-sized fields together
  • Remember that sequences are preceded by a long, which must be aligned on a 4-byte boundary

Note that this a useful optimization if you have limited bandwidth, but is not necessary for the majority of systems.