-
Notifications
You must be signed in to change notification settings - Fork 60
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Union support not optimal in memory usage [13725] #39
Comments
Is this optimization still on the table? I'm interested in this feature. It looks to me that this could be done quite simply using an anonymous union:[https://en.cppreference.com/w/cpp/language/union] Basically, the emitted code is already a variant (aka discriminating union), in that it has an enum type for the active member, followed by the allowed member types. Simply surrounding these types in |
To be explicit, surrounding here with |
It is not as simple when string or structured types are used within the union, at that moment initialization and destruction requires additional code |
Yes, and std::vector for the sequence too. The easier path would be to use std::variant which provides exactly the discriminating union type needed, but it can be an up-hill battle to get c++17 features accepted. |
I see that this is a proposal for achieving a more optimal behavior regarding memory usage. For that reason, I proceed and convert this issue to a discussion. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
The current code generation for IDL unions generates a class with for each case a plain member resulting in memory usage for all types independent of the discriminator, see for example https://github.com/eProsima/Fast-DDS/blob/6fa5e5cc8abcf506e70be203934bd3c522bd3edf/test/xtypes/idl/Types.h#L4693. This leads to a lot of memory usage when larger unions are used. This can be done much more optimized by using an union internally, see for example https://github.com/RemedyIT/idl2cpp11/blob/master/examples/union/testC.h for a possible solution
The text was updated successfully, but these errors were encountered: