[omniORB] freeing out-parameters

vonWedel@lfpt.rwth-aachen.de vonWedel@lfpt.rwth-aachen.de
Wed, 31 Jan 2001 09:56:48 +0100


Dies ist eine mehrteilige Nachricht im MIME-Format.
--=_alternative 0030D553C12569E5_=
Content-Type: text/plain; charset="us-ascii"

Hello,

To solve the problem you describe, the CORBA language mapping for C++ 
specifies
that out and return parameters are freed after the ORB has marshalled 
them. Whereas
you had to create and return a copy manually according earlier versions of 
the standard,
you can now use the _retn() method to do the job. I suppose something like 
the following
should be working (and also circumvents using the operator* on the 
sequence object):

  void CPze::getProjectList(const char* von, const char* bis, 
  CORBA::Boolean sortById, ObjList_out projects)
  {
    // ...
    ObjList_var p_list = new ObjList;
    projects->length (size);  // CORBA-size eintragen...

    // ...

    projects = p_list._retn()
  }

This will use a _var object for a sequence so you can directly access it
using p_list[index] and returns a copy of it which is freed by the CORBA
runtime system. The local contents are freed when the _var variable goes
out of scope.

MfG
Lars von Wedel






"Weigl Christoph" <christoph.weigl@fee.de>
Sent by: owner-omniorb-list@uk.research.att.com
31/01/01 09:24

 
        To:     omniorb-list@uk.research.att.com
        cc: 
        Subject:        [omniORB] freeing out-parameters


Hi,
I'm sure this question has been asked before, but I can't find the 
postings and the following problem is very important for us:
We have a server which uses sequences as out-params to pass 
results to clients.

  void CPze::getProjectList(const char* von, const char* bis, 
  CORBA::Boolean sortById, ObjList_out projects)
  {
    (...)
    projects = new ObjList;
    projects->length (size);  // CORBA-size eintragen...

    while (....)
    {
      ObjDescr *x = new ObjDescr;
      // get a pointer to a p object from a database...

      CString s;
      s.Format ("%d", p->ID);
      x->Id = CORBA::string_dup (s);
      x->Bezeichnung = CORBA::string_dup (p->Bezeichnung);
      (*projects)[index++] = *x;
      (...)
     // delete the p-pointer
  }

  ObjList and ObjDescr are defined in the .idl-file:
 
  struct ObjDescr
  {
    string Id;
    string Bezeichnung;
  }; 
  typedef sequence <ObjDescr> ObjList;
 
Now, my problem is that the server seems to eat the "out-param" 
memory. In my opinion, the orb sould be able to delete all allocated 
memory after passing the out-param to the client (am I wrong 
here?).
What must i do to get this memory freed?


Thanks for reading,
Chris

Mfg.

Christoph Weigl
Tel.  09672 506-178
Mail: Christoph.Weigl@FEE.De





--=_alternative 0030D553C12569E5_=
Content-Type: text/html; charset="us-ascii"




<br><font size=2 face="sans-serif">Hello,</font>
<br>
<br><font size=2 face="sans-serif">To solve the problem you describe, the CORBA language mapping for C++ specifies</font>
<br><font size=2 face="sans-serif">that out and return parameters are freed after the ORB has marshalled them. Whereas</font>
<br><font size=2 face="sans-serif">you had to create and return a copy manually according earlier versions of the standard,</font>
<br><font size=2 face="sans-serif">you can now use the _retn() method to do the job. I suppose something like the following</font>
<br><font size=2 face="sans-serif">should be working (and also circumvents using the operator* on the sequence object):</font>
<br>
<br><font size=2 face="Courier New">&nbsp; void CPze::getProjectList(const char* von, const char* bis, &nbsp; &nbsp; &nbsp; <br>
 &nbsp;CORBA::Boolean sortById, ObjList_out projects)<br>
 &nbsp;{<br>
 &nbsp; &nbsp;// ...<br>
 &nbsp; &nbsp;ObjList_var p_list = new ObjList;<br>
 &nbsp; &nbsp;projects-&gt;length (size); &nbsp;// CORBA-size eintragen...</font>
<br>
<br><font size=2 face="Courier New">&nbsp; &nbsp; // ...</font>
<br>
<br><font size=2 face="Courier New">&nbsp; &nbsp; projects = p_list._retn()</font>
<br><font size=2 face="Courier New">&nbsp; }</font>
<br>
<br><font size=2 face="sans-serif">This will use a _var object for a sequence so you can directly access it</font>
<br><font size=2 face="sans-serif">using p_list[index] and returns a copy of it which is freed by the CORBA</font>
<br><font size=2 face="sans-serif">runtime system. The local contents are freed when the _var variable goes</font>
<br><font size=2 face="sans-serif">out of scope.</font>
<br>
<br><font size=2 face="sans-serif">MfG</font>
<br><font size=2 face="sans-serif">Lars von Wedel</font>
<br><font size=2 face="Courier New"><br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td>
<td><font size=2 face="sans-serif"><b>&quot;Weigl Christoph&quot; &lt;christoph.weigl@fee.de&gt;</b></font>
<br><font size=2 face="sans-serif">Sent by: owner-omniorb-list@uk.research.att.com</font>
<p><font size=2 face="sans-serif">31/01/01 09:24</font>
<br>
<td><font size=1 face="Arial">&nbsp; &nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; To: &nbsp; &nbsp; &nbsp; &nbsp;omniorb-list@uk.research.att.com</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; cc: &nbsp; &nbsp; &nbsp; &nbsp;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Subject: &nbsp; &nbsp; &nbsp; &nbsp;[omniORB] freeing out-parameters</font></table>
<br>
<br><font size=2 face="Courier New"><br>
Hi,<br>
I'm sure this question has been asked before, but I can't find the <br>
postings and the following problem is very important for us:<br>
We have a server which uses sequences as out-params to pass <br>
results to clients.<br>
<br>
 &nbsp;void CPze::getProjectList(const char* von, const char* bis, &nbsp; &nbsp; &nbsp; <br>
 &nbsp;CORBA::Boolean sortById, ObjList_out projects)<br>
 &nbsp;{<br>
 &nbsp; &nbsp;(...)<br>
 &nbsp; &nbsp;projects = new ObjList;<br>
 &nbsp; &nbsp;projects-&gt;length (size); &nbsp;// CORBA-size eintragen...<br>
<br>
 &nbsp; &nbsp;while (....)<br>
 &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp;ObjDescr *x = new ObjDescr;<br>
 &nbsp; &nbsp; &nbsp;// get a pointer to a p object from a database...<br>
<br>
 &nbsp; &nbsp; &nbsp;CString s;<br>
 &nbsp; &nbsp; &nbsp;s.Format (&quot;%d&quot;, p-&gt;ID);<br>
 &nbsp; &nbsp; &nbsp;x-&gt;Id = CORBA::string_dup (s);<br>
 &nbsp; &nbsp; &nbsp;x-&gt;Bezeichnung = CORBA::string_dup (p-&gt;Bezeichnung);<br>
 &nbsp; &nbsp; &nbsp;(*projects)[index++] = *x;<br>
 &nbsp; &nbsp; &nbsp;(...)<br>
 &nbsp; &nbsp; // delete the p-pointer<br>
 &nbsp;}<br>
<br>
 &nbsp;ObjList and ObjDescr are defined in the .idl-file:<br>
 &nbsp;<br>
 &nbsp;struct ObjDescr<br>
 &nbsp;{<br>
 &nbsp; &nbsp;string Id;<br>
 &nbsp; &nbsp;string Bezeichnung;<br>
 &nbsp;}; &nbsp;<br>
 &nbsp;typedef sequence &lt;ObjDescr&gt; ObjList;<br>
 <br>
Now, my problem is that the server seems to eat the &quot;out-param&quot; <br>
memory. In my opinion, the orb sould be able to delete all allocated <br>
memory after passing the out-param to the client (am I wrong <br>
here?).<br>
What must i do to get this memory freed?<br>
<br>
<br>
Thanks for reading,<br>
Chris<br>
<br>
Mfg.<br>
<br>
Christoph Weigl<br>
Tel. &nbsp;09672 506-178<br>
Mail: Christoph.Weigl@FEE.De<br>
<br>
<br>
</font>
<br>
<br>
--=_alternative 0030D553C12569E5_=--