Discussion:
Who has to free Any pointer from CosEventComm::PullSupplier::pull()?
Schmidt Thomas
2009-01-18 14:15:23 UTC
Permalink
Hi,


when writing some pull-event supplier I think I've to return a
dynamically allocated Any pointer. Who has to take care of freeing
this variable? F.e. some code fragments from my example server
program "SinusGenerator":

CORBA::Any *SinusGenerator_impl::pull()
{
CORBA::Any &theValue = *new CORBA::Any; // GNU raises bad_alloc
() in case
CORBA::ULong currentPos = currentSamplePosPostInc();
DataPoint dp = { currentPos, _curveSamples[currentPos] };

theValue <<= dp;

return &theValue;

} /* pull() */

while DataPoint is defined as follows (DataPoint.idl):

struct DataPoint
{
unsigned long x;
double y;

} /* struct DataPoint */;

Returning some statically allocated variable in the above example
seems not the best idea when writing reentrant code.

Both parts, server and client, of my little experimental environment
work well. But I wonder who will free the variable 'theValue'.


Thanks Thomas

--
Thomas Schmidt
Schneiderstr. 16
D-29575 Altenmedingen
Phone: +49-5807-209976
Cellular: +49-172-3011505
Skype: ThCSchmidt
Email: ***@vodafone.de
PGP: Key-ID: 0x810B6206
Karel Gardas
2009-01-19 17:31:21 UTC
Permalink
Hi,

short answer is: caller is responsible for freeing memory. Long answer
is contained in any decent CORBA book dealing with C++ mapping. My
favorite is Advanced CORBA Programming in C++ by Henning/Vinoski.

Cheers,
Karel
Post by Schmidt Thomas
Hi,
when writing some pull-event supplier I think I've to return a
dynamically allocated Any pointer. Who has to take care of freeing this
variable? F.e. some code fragments from my example server program
CORBA::Any *SinusGenerator_impl::pull()
{
CORBA::Any &theValue = *new CORBA::Any; // GNU raises
bad_alloc() in case
CORBA::ULong currentPos = currentSamplePosPostInc();
DataPoint dp = { currentPos, _curveSamples[currentPos] };
theValue <<= dp;
return &theValue;
} /* pull() */
struct DataPoint
{
unsigned long x;
double y;
} /* struct DataPoint */;
Returning some statically allocated variable in the above example seems
not the best idea when writing reentrant code.
Both parts, server and client, of my little experimental environment
work well. But I wonder who will free the variable 'theValue'.
Thanks Thomas
--
Thomas Schmidt
Schneiderstr. 16
D-29575 Altenmedingen
Phone: +49-5807-209976
Cellular: +49-172-3011505
Skype: ThCSchmidt
PGP: Key-ID: 0x810B6206
------------------------------------------------------------------------
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
Karel Gardas ***@objectsecurity.com
ObjectSecurity Ltd. http://www.objectsecurity.com
Loading...