[omniORB] Problem using Any constructor

Duncan Grisby dgrisby@uk.research.att.com
Fri, 06 Aug 1999 13:18:52 +0100


On Thursday 5 August, Ernie van der Meer wrote:

> I have been trying to insert a structure into an Any without having the
> Any copy the value. I need to insert objects of several tens of megabytes,
> so I can't afford to have them copied all over the place. I found the
> following CORBA::Any constructor:
> 
>     CORBA::Any::Any(TypeCode_ptr tc, void* value, Boolean release)

You shouldn't use that constructor -- it's not type safe and has been
deprecated. It will disappear in future CORBA specs.

> This looks like the thing I need. I use the following IDL for my test:
> 
>     typedef sequence<double> DoubleSeq;
> 
>     struct Point
>     {
>       long x, y, z;
>       DoubleSeq ds;
>     };
> 
>     interface Tester
>     {
>       any getVal();
>     };

> In my server, I implement the getVal() member function as follows:
> 
>     CORBA::Any *getVal()
>     {
>       Point *p = new Point;
>       p->x = 10.0; 
>       p->y = 11.0; 
>       p->z = 12.0; 
>       p->ds.length(5);
>       p->ds[0] = 1.0;
[...]

At this stage, simply do:

  CORBA::Any *ret = new CORBA::Any()
  (*ret) <<= p

Since p is a pointer to a struct, the Any will assume ownership of it,
so there won't be any copying.

HTH,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --