0

I'm told that DDS maintains a reference to DTOs created when using the example code here:

 public void on_data_available(DataReader reader) {
        HelloWorldDataReader HelloWorldReader =
            (HelloWorldDataReader)reader;

        try {
            HelloWorldReader.take(
                _dataSeq, _infoSeq,
                ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                SampleStateKind.ANY_SAMPLE_STATE,
                ViewStateKind.ANY_VIEW_STATE,
                InstanceStateKind.ANY_INSTANCE_STATE);

            for(int i = 0; i < _dataSeq.size(); ++i) {
                SampleInfo info = (SampleInfo)_infoSeq.get(i);

                if (info.valid_data) {
                    System.out.println(
                        ((HelloWorld)_dataSeq.get(i)).toString("Received",0));


                }
            }
        } catch (RETCODE_NO_DATA noData) {
            // No data to process
        } finally {
            HelloWorldReader.return_loan(_dataSeq, _infoSeq);
        }
    }
}

Do I need to use the copy_from method prior to passing the DTO to the rest of my code? The explanation given was that RTI maintains a reference to the DTO and will simply update the fields when new data is received instead of creating a new HelloWorld DTO. The explanation stated the DTOs wouldn't operate properly unless it was explicitely released by first performing a copy (so I'm not holding a reference to the original) and calling return_loan on the reader. This doesn't make sense to me as I'd expect the references to be cleared once the sequence is cleared.

Is this accurate? Do I actually need to copy every single time a DTO comes in? I'd prefer to minimize overhead if possible since these DTOs will be sent at a relatively high rate.

Dodd10x
  • 3,344
  • 1
  • 18
  • 27

1 Answers1

0

Yes (copy_from), or extract the information you are looking for and then release_loan.

Internally you are using data managed by the middleware.

When you are between the take (or read) and the release_loan, it is guaranteed that the data is in a consistent state.

If you hold a reference to internal (DDS) memory, and release_loan, how do you know that the data you look at (at a later time) is not in the process of being updated? (in Java you get concurrent memory access exceptions in any case).

Keep in mind that the internals you are working with are not Java, they are held in a c library (a JNI connection). The only way that Connext will ensure that the data is consistent and coherent is through the loan/release_loan mechanisms.

So: Deep copy and then release the loan.

rip...
  • 996
  • 5
  • 20