[omniORB] Reference passing
baileyk@schneider.com
baileyk@schneider.com
Thu Aug 8 13:57:01 2002
You do need to duplicate the reference. A _ptr type does not have
ownership semantics, as it is likely just a raw pointer. Some reference
counting schemes start an object with a zero count and any time a new
handle attaches, the ref-count is incremented (in the assignment operator).
The CORBA scheme starts a reference count at one and the application is
responsible for incrementing it (via a _duplicate() call). The _var types
do not increment the count when they are assigned a _ptr instance. However
if one _var is assigned another _var, then the ref count does get
incremented for you.
So when starting with a _ptr, do the duplicate yourself, but if you copy a
_var, then don't. I think your code should read
void BarrierSrv_i::registerInBarrierServer( OrbiMan_ptr newManager){
orbiMan_var = OrbiMan::_duplicate(newManager);
}
The call of _duplicate through the _var instance probably works, but the
above is the correct way, since _duplicate is a static method.
Kendall
Jacek Nowak
<jnowak@ernie.icslab.a To: <omniorb-list@realvnc.com>
gh.edu.pl> cc:
Sent by: Fax to:
omniorb-list-admin@rea Subject: [omniORB] Reference passing
lvnc.com
08/08/2002 05:22 AM
I have the following problem:
I pass a _ptr reference to an object as an 'in' parameter of a function
and try keep a copy of it in a _var. Something like this:
void BarrierSrv_i::registerInBarrierServer( OrbiMan_ptr newManager){
orbiMan_var = newManager_ptr;
//orbiMan_var->_duplicate( orbiMan_var );
}
If I don't call _duplicate explicitly the reference gets deleted when
leaving the function, and the next attemp to use the _var reference causes
segmentation fault.
void BarrierSrv_i::test( ){
orbiMan_var->ping(); // <- Segmentation fault
}
Is this correct behavior? I mean, do I have to call _duplicate explicitly?
I always thought _duplicate is called when the _var takes over ownership
from the _ptr.
Thanks,
Jacek
_______________________________________________
omniORB-list mailing list
omniORB-list@realvnc.com
http://www.realvnc.com/mailman/listinfo/omniorb-list