I’m looking for feedback about an problem/proposal!
I find when writing controllers or other performance sensitive c++ code where I want to publish something, that I have to make a compromise between memory efficiency and semantics/correctness. Specifically, I would like my code to behave as if I am creating a new message from scratch each time, but without actually doing that. But right now I either have to store/reuse a message (like realtime publisher does), or create a new message each time. Creating a new one will get rid of any memory (especially heap memory allocated by the lists in the message). Reusing one risks leaving some fields or subfields with stale data from the previous iteration.
Does anyone have tips for me here?
Finally, I would propose that the code gen for cpp messages could generate a clear method, which would clear all lists in the message and recursively for sub messages, plus also maybe resetting any other types to their default values. Thoughts?