[Ace-users] [tao-users] _duplicate on ORB
Sumant Tambe
sutambe at dre.vanderbilt.edu
Wed Jan 2 00:35:13 CST 2008
Hi,
Correct me if I am wrong but one advantage of calling _duplicate over
just storing _ptr is that you can store the ORB/POA references in global
or static objects. Using _duplicate would not cause premature deletion
of ORB/POA before destructors of all static/global objects (that hold
references to ORB/POA) are finished at the end of a program. It will be
destroyed only when the last static/global object is destroyed.
Thanks,
Sumant.
Chris Cleeland wrote:
>
> On Dec 27, 2007, at 7:46 AM, Douglas C. Schmidt wrote:
>>> My question is not specific to any ACE TAO version.
>>> I have read many examples in the examples directory and also from
>>> "Advanced corba programming with c++" book.
>>>
>>> While creating a servant all examples do a _duplicate of the orb
>>> and store it in a member variable.
>>> Why this duplicate is required?
>>
>> It's not required - it's just an idiom for simplifying memory management.
>>
>>> Can we just keep a _ptr to ORB?
>>
>> Sure - as long as you have strict control over when to delete the ORB.
>>
>>> I have not seen doing same while storing POA references. They are
>>> stored in _ptr. Why is this?
>>
>> I don't think the POA references are passed as parameters as much as the
>> ORB references are.
>
> To expand on Doug's answer, the _duplicate() manages reference counts on
> Object References. When the reference count for a CORBA Object
> Reference falls to zero, that reference is typically deleted. Any _ptrs
> left that still point to the reference are now dangling pointers and
> could cause errors.
>
> All of this is an artifact of the C++ mapping's memory management model,
> and the Henning & Vinoski book addresses this topic--as well as the
> entire model--very well. Often, CORBA training classes will go into
> greater detail on memory management (OCI's does), as memory management
> mistakes account for probably 80% of the problems we encounter in CORBA
> applications.
>
> As to why POA references aren't duplicated--I don't know. There are
> many possible reasons, ranging from "it's a mistake" to "it's using a
> different technique to manage reference counts".
>
> The important point to take home, though is what Doug said here:
>
>>> What should be the general practice followed while storing ORB and
>>> POA references in objects as a member variables.
>>
>> You should follow whatever pattern that (1) you understand and (2)
>> prevents memory leaks/corruption.
>
> I have found that using _var as member variable types, and using the
> "_ptr" style for parameters works best for me.
>
> ---
> Chris Cleeland, Principal Software Engineer
> http://www.theaceorb.com AND http://www.ociweb.com
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> tao-users mailing list
> tao-users at mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/tao-users
More information about the Ace-users
mailing list