On 11/25/02 10:06 AM, "Peter Dimov" <[EMAIL PROTECTED]> wrote:

>> One thing missing from intrusive_ptr as implemented in 1.29 is the ability
>> to avoid the add_ref at construction time.
>> 
>> There are a number of APIs using refcounted opaque types (Apple in
>> particular is fond of them) in which a function call will "pre-acquire" a
>> reference for the caller. In many OS X APIs, this is designated by use of
>> the term "Copy" or "Create" instead of "Get". If you think about it,
> adding
>> a ref before returning is necessary for flat C APIs to avoid thread
>> synchronization problems.
> 
> [...]
> 
>> This would allow one to use this style of code:
>> 
>>     intrusive_ptr<OpaqueRefCountedString> s =
>>         dont_addref(CopyMenuTitle(m));
> 
> intrusive_ptr<OpaqueRefCountedString> s = CopyMenuTitle(m);
> s->Release(); // or however it's spelled
> 
> ?
> 
Calling Release is semantically correct, but inefficient (in some cases
prohibitively so), since we're dealing with C API calls made over a library
boundary. In particular, Release() is not going to get inlined.

Additionally, this idiom is so common in certain OS's that a clear one-line
solution would be preferable. Perhaps "reuse_ref" would be a better choice
than "dont_addref"?

thanks,

jim

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to