Python Sequence Memory Management

4 posts / 0 new
Last post
Offline
Last seen: 3 weeks 5 days ago
Joined: 09/07/2022
Posts: 3
Python Sequence Memory Management

Hello,

I have a question regarding sequences and shared memory. After calling topic.read(), a loanedSamples object is returned which is a list containing references to each LoanedSample. We must call return_loan() to return the loaned sequence back to Connext DDS for the recieve queue. My question is, how can we continue to access the data after calling return_loan()? If we return the buffer back to DDS, the references to the data points can be overwritten. Do we need to create a deep copy of the data before we call return_loan? if so, does the RTI DDS Python Package provide a way to do that? The C++ implementation allows a user to pass it's own sequence to the read/take operations, but I do not see that option in the python api. Thanks!

Offline
Last seen: 1 hour 11 min ago
Joined: 04/02/2013
Posts: 189

Hi,

If you are on version 7.0.0 and using Python classes or IDL types, the read() and take() operations return copies, not loans.

If you are using DynamicData, you have to make a deep copy if you want to keep the data after the loan is returned. You can do that like this:

copy = dds.DynamicData(original)

 

Alex

Offline
Last seen: 3 weeks 5 days ago
Joined: 09/07/2022
Posts: 3

Hi Alex,

I am on version 5.3.1. copy = dds.DynamicData(original) seems to expect a DynamicType, however the orginal read from the topic returns a sequence that contains 'DynamicData' objects - therefore, 'copy=dds.DynamicData(original)' throws an error. Is there another way to create a deep copy, or should I be passing a different argument to dds.DynamicData? I am used to passing it a type so that it creates an empty data structure.

Offline
Last seen: 1 hour 11 min ago
Joined: 04/02/2013
Posts: 189

Which version of the Python API are you using (pip show rti)? Starting in 0.1.5 the init function I suggest should be available. I strongly recommend upgrading the Python API to 7.0.0.