Memory management when writing samples

4 posts / 0 new
Last post
Offline
Last seen: 3 years 7 months ago
Joined: 07/27/2014
Posts: 5
Memory management when writing samples

I'm currently using DDS Connext v5.0.0, with C++ application.

Are there any restrictions on when a data sample can be deleted after calling the DataWriter write() method?

My application crashes (with seg fault) if I delete the sample immediately after it has been sent, and the sample contains a populated sequence.

Regards John

 

Organization:
Offline
Last seen: 1 day 13 hours ago
Joined: 01/15/2013
Posts: 89

Hi Harry,

Are you loaning some of the sequences' contents? You won't be able to delete samples right after writing of they are using loaned sequences. In any other case, it should be fine to delete the sample right after writing.

Thanks,

Juanlu

Offline
Last seen: 3 years 7 months ago
Joined: 07/27/2014
Posts: 5

It turns out that one of my data structures contained an uninitialised string.

By initialising the string using DDS_String_dup() the problem has disappeared?

I understand that calling xxxxTypeSupport::create_data() allocates memory for strings? Whereas objects created on the stack are not. Perhaps the DDS was attempting to free unitilialized memory when the object was destroyed?

Hopefully future versions of DDS replace string types (char*) with and STL string, as it currently feels very clunky?

Cheers John

 

jwillemsen's picture
Offline
Last seen: 8 months 1 week ago
Joined: 09/24/2013
Posts: 53

The new DDS C++ PSM and also the IDL to C++11 language mapping both map IDL strings to std::string (or to a type delivering the same API)