Can we dynamically create and free data writer?

2 posts / 0 new
Last post
Joined: 03/25/2018
Posts: 10
Can we dynamically create and free data writer?


Currently, all data writers are created before use and that consumes memory. Some topics (and thus data writers) are events that only be invoked under certain scenarios, and can be created when necessary and release after used.

Is there a way to support dynamic creation and release of data writers, just like malloc() and free() ?

I am using C for my development in DDS Micro, and DDS_Publisher_create_datawriter() to create the data writer.

Second question is: Must a topic assigned to one data writer? Can topics share a data writer?



sara's picture
Joined: 01/16/2013
Posts: 116

Hi Chee-Beng,

You can delete the DW using the same API that you're mentioning: DDS_Publisher_delete_datawriter() (more info here).

However, take into account that for data to be sent from a newly created DW you need to wait for Discovery to happen. It's not automatic that a DW is created than it's discovered by DRs in the other side of the communication. So deleting and creating entities is not always the answer and may create other problems in your system.

And to your second question, each topic is associated with only one Topic, yes. You could use the same DomainParticipant and Publisher, which are heavier entities. Overall, I would recommend we review where the memory is going before suggesting anything else.

I've seen you have a Support case on this. Let's work through that and maybe put here the conclusions once we understand better your use case.

All the best,