sequences containig object references
Sai-Lai Lo
S.Lo@orl.co.uk
28 Oct 1997 12:14:15 +0000
Bernd Daum <daum@dik.maschinenbau.tu-darmstadt.de> writes:
> interface List_of_Requirements_OB {
> void get_Requirements(in string name, out T_list list);
> };
>
>
> C++ -code:
>
> Corba-Client:
> . .
> T_list_var* list = new T_list();
^^^^^^^^^^^^^
This is not necessary because the second
argument is an OUT. The sequence returned by the new
operator would be deallocated and overwritten
internally by the return value of get_Requirements.
However, this is harmless under omniORB. In other
ORBs, for example Orbix, their handling of T_var
arguments may not be fully compliant and may result
in a memory leak if you assign a sequence to a T_var
and then use the T_var as an OUT argument.
>
> Corba-server: implementation of the server method:
>
> List_of_Requirements_OB::get_Requirements( const char * name, T_list *&
> list) {
> .
> .
> list = new T_list();
> list->length(0);
>
> for (CORBA::ULong i=0;iter.next()!=0;i++)
> {
> Requirement_OB_i *reqobj = new Requirement_OB_i(); //instantiation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You have to call reqobj->_obj_is_ready(boa) to finish the
instantiation of the object implementation. From this point onwards,
the BOA will manage the object and dispatch calls to it.
> reqobj->name("temperature"); // populating the object
> list->length(i+1);
> (*list)[i] = reqobj; // inserting in the 'sequence'
^^^^^^^^^^^^^^^^^^^^
Should use (*list)[i] = reqobj->_this(); instead.
1. It is a bad practice and non-portable to assume that
an object implementation can be implicitly casted to an
object reference.
2. CORBA C++ mapping's memory management rule dictates that
for an OUT sequence argument, the callee (your server) is
responsible for the allocating the storage and the caller
(your client) is responsible for releasing the storage.
When the client is remote, the callee is the stub code.
Hence the storage of the sequence would be freed by the stub
code when the sequence has been marshalled onto the network
connection. In this example, a CORBA::release() would be
called in the stub on each of the element of the sequence.
Regards,
Sai-Lai
--
E-mail: S.Lo@orl.co.uk | Olivetti & Oracle Research Lab
| 24a Trumpington Street
Tel: +44 223 343000 | Cambridge CB2 1QA
Fax: +44 223 313542 | ENGLAND