[omniORB] Corba union waste of space?

Michael Teske subscribe at teskor.de
Tue Jan 6 16:06:53 GMT 2009


Bruce Visscher wrote:
> On Mon, Dec 8, 2008 at 6:18 AM, Duncan Grisby <duncan at grisby.org> wrote:
>> On Thursday 4 December, Michael Teske wrote:
>> [...]
>>> This seems like a bug (waste of space) to me or is there any reason
>>> that the string members do not go into the union? Our real-life used
>>> union has even more types... As I mentioned in an earlier post, we're
>>> porting our system from orbacus, which uses pointers here so they fit
>>> into the C++ union data type (I suppose the complex types are not
>>> allowed in a C++union?).
>> The String_members cannot go in the union, because you can't put such
>> things in a C++ union. It certainly would be possible to store pointers
>> to String_members (and other complex types) instead, and they could go
>> in the union. I'd welcome a patch that did that.
>>
>> The place to start attacking it is to look in
>> src/lib/omniORB/omniidl_be/cxx/header/template.py which defines the
>> templates that go in the C++ headers. From there, search the code for
>> the places that use the templates. I'm afraid that some of the C++
>> back-end code is rather ugly...
> 
> Thanks Duncan.
> 
> Michael, one thing I would suggest (inspired by Teemu's post) is that
> if you are going to spend the time doing this you consider an
> implementation that utilizes placement new and explicit calls to the
> destructor (as boost variant apparently does).
> 
> A brief outline would be (using String_member as an example) declare a
> char array[sizeof(String_member)] as a union member.  Also declare
> (but do not use) something with maximal alignment requirements
> (void*'s and/or long long are good choices you could actually use
> both).  This would ensure that the storage will be aligned on a 32 or
> 64 bit boundary.  Then use placement new to initialize the storage and
> an explicit call to the destructor "deinitialize" the storage.  This
> would avoid an extra memory allocation.  Use
> reinterpret_cast<String_member*> on the char pointer in the
> String_member accessor.

Hi Bruce, hi Duncan,

finally I found the time to do it. Unfortunately I ran into 2 problems, one can be
solved with an ugly trick, but for the other one I can't find an easy solution:

1. (difficult): In skutil.py/unmarshall I need to find out if a string (or other
types, to be done later) is a member of a union or not (in the first case I have
to cast the char array to ::CORBA::String_member * and dereference it, in the
other case I leave the code as it is), but I cannot find a way to get this info.

2. (ugly trick): In order for placement new to work 100% correct, I need to call
destructors explicitely. Unfortunately I only have the type name
:CORBA::String_member and need to call ~_CORBA_String_member(), because it's a
typedef. My ugly hack is to replace ::CORBA:: with _CORBA_, but I really do not
like it, as it will probably break with other types.


Any ideas?

Greetings,
  Michael




More information about the omniORB-list mailing list