[omniORB] Question about unions and c++ mapping

Duncan Grisby duncan at grisby.org
Fri Jan 8 13:40:32 GMT 2010


On Wed, 2009-12-30 at 15:41 -0500, david.jobet at americas.bnpparibas.com
wrote:

[...]
> Basically, this is what I would like to write : (#1) 
>   MyUnion &union = seq[no]; // seq is a sequence of MyUnion 
>   union._d(myEnum2); // oops, discriminant not initialized yet 
>   FatObject &fat = union.fat(); 
>   initializeFat(fat); 
> 
> But it does not work, the correct compliant way is : (#2) 
>   MyUnion &union = seq[no]; // seq is a sequence of MyUnion 
>   FatObject fat; 
>   initializeFat(fat); 
>   union.fat(fat); // initialize discriminant and performs deep copy 
> 
> Is there any way to avoid the deep copy ? It can be costly if the
> sequence is very long. 
> Is there any good reason the spec disallow writing code #1 ? 

The mapping spec for unions is ugly in lots of ways, and this is one of
them. I don't know why there isn't support for what you want.

> Looking at the code generated by omniidl, it would be completly
> possible and safe to do it in the #1 way, but I would have to manually
> patch the generated code to explictly allow it. 
> Any thought about it ? 

You're right, it could be done safely. You can either modify the
generated code or, if you feel like a more complete approach, modify the
omniidl back-end to generate different code. If you want to do that, let
me know so I can give you some pointers and help you do it in a way that
can be incorporated in the release.

Another thing that is probably relevant to you is that omniORB 4.1 (and
previous releases) sets aside space for all union members in some cases,
meaning that a lot of space can be wasted. Ages ago, Michael Teske sent
me a patch that partially fix that. I've extended / modified it to be
more efficient with storage in all cases, but I hadn't got around to
checking it in. Your post has prompted me to finally do so, so if you
get the current trunk from svn, you'll find the new mapping
implementation.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --





More information about the omniORB-list mailing list