[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"> void CPze::getProjectList(const char* von, const char* bis, <br>
CORBA::Boolean sortById, ObjList_out projects)<br>
{<br>
// ...<br>
ObjList_var p_list = new ObjList;<br>
projects->length (size); // CORBA-size eintragen...</font>
<br>
<br><font size=2 face="Courier New"> // ...</font>
<br>
<br><font size=2 face="Courier New"> projects = p_list._retn()</font>
<br><font size=2 face="Courier New"> }</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>"Weigl Christoph" <christoph.weigl@fee.de></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"> </font>
<br><font size=2 face="sans-serif"> To: omniorb-list@uk.research.att.com</font>
<br><font size=2 face="sans-serif"> cc: </font>
<br><font size=2 face="sans-serif"> Subject: [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>
void CPze::getProjectList(const char* von, const char* bis, <br>
CORBA::Boolean sortById, ObjList_out projects)<br>
{<br>
(...)<br>
projects = new ObjList;<br>
projects->length (size); // CORBA-size eintragen...<br>
<br>
while (....)<br>
{<br>
ObjDescr *x = new ObjDescr;<br>
// get a pointer to a p object from a database...<br>
<br>
CString s;<br>
s.Format ("%d", p->ID);<br>
x->Id = CORBA::string_dup (s);<br>
x->Bezeichnung = CORBA::string_dup (p->Bezeichnung);<br>
(*projects)[index++] = *x;<br>
(...)<br>
// delete the p-pointer<br>
}<br>
<br>
ObjList and ObjDescr are defined in the .idl-file:<br>
<br>
struct ObjDescr<br>
{<br>
string Id;<br>
string Bezeichnung;<br>
}; <br>
typedef sequence <ObjDescr> ObjList;<br>
<br>
Now, my problem is that the server seems to eat the "out-param" <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. 09672 506-178<br>
Mail: Christoph.Weigl@FEE.De<br>
<br>
<br>
</font>
<br>
<br>
--=_alternative 0030D553C12569E5_=--