[omniORB] A question about sequences

Sai-Lai Lo S.Lo@uk.research.att.com
05 Aug 1999 10:24:41 +0100


Tony,

While Ben's explanation is correct, your client code is also right if the
ORB support CORBA 2.2 or 2.3 C++ mapping.

Client code:
===========

void f(A_ptr obj)
{
  MySequence_var v;
  obj->doSomething(v.out());
}

This works fine with omniORB-2.8.0pre1 as it is the first omniORB release
to support the 2.3 mapping. I don't think the code can be compiled with omniORB
2.7.1 because the mapping is still CORBA 2.0.

Having said that, this is also perfectly legal code in any CORBA versions:

void f(A_ptr obj)
{
  MySequence_var v;
  obj->doSomething(v);
}

And will work with omniORB 2.7.1 and 2.8.0. The drawback of using this code
is that some commercial ORBs do not handle type conversion correctly and
could result in memory leak (not in this particular example) if the _var
variable is already managing a sequence pointer. omniORB handles the
conversion and memory management correctly. If you worry about portability,
make sure that the _var variable passed to the invocation is not managing a
sequence ptr.

Server code:
===========

With CORBA 2.3 C++ mapping, the following can be written:

void A::doSomething(MySequence*& param)
{
  MySequence_var v;
  v = new MySequence();
  v->length(10);
  ... // populate v

  param = v._retn();
}

If at any time before the call to _retn() an exception is thrown and the
stack unwinded, the sequence ptr managed by the _var variable would be
clean up automatically by the dtor.

Sai-Lai


-- 
Sai-Lai Lo                                   S.Lo@uk.research.att.com
AT&T Laboratories Cambridge           WWW:   http://www.uk.research.att.com 
24a Trumpington Street                Tel:   +44 1223 343000
Cambridge CB2 1QA                     Fax:   +44 1223 313542
ENGLAND