--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
It's probably not a huge cost. However, the proposed change would make it impossible to avoid the extra AddRef/Release--from what I remember, example 3 is currently discouraged/banned for being too subtle. It'd be nice to make this change while still allowing people to easily avoid refcount churn if they wanted, whether it involves allowing example 3 or adding move semantics.
On Tue, Jan 17, 2012 at 6:06 PM, Daniel Cheng <dch...@chromium.org> wrote:It's probably not a huge cost. However, the proposed change would make it impossible to avoid the extra AddRef/Release--from what I remember, example 3 is currently discouraged/banned for being too subtle. It'd be nice to make this change while still allowing people to easily avoid refcount churn if they wanted, whether it involves allowing example 3 or adding move semantics.Huh...I didn't know example 3 was discouraged. For the record, it works completely correctly. The Callback object owns the actual ref-pointer, and the function invocation only gets a const-reference to it.
On Jan 18, 2012 8:08 AM, "David Michael" <dmichael@chromium.org> wrote:
>
> On Tue, Jan 17, 2012 at 7:10 PM, Albert J. Wong (王重傑) <ajwong@chromium.org> wrote:
>>
>> On Tue, Jan 17, 2012 at 6:06 PM, Daniel Cheng <dcheng@chromium.org> wrote:
>>>
>>> It's probably not a huge cost. However, the proposed change would make it impossible to avoid the extra AddRef/Release--from what I remember, example 3 is currently discouraged/banned for being too subtle. It'd be nice to make this change while still allowing people to easily avoid refcount churn if they wanted, whether it involves allowing example 3 or adding move semantics.
>>
>>
>> Huh...I didn't know example 3 was discouraged. For the record, it works completely correctly. The Callback object owns the actual ref-pointer, and the function invocation only gets a const-reference to it.
>
> ...and the reference counting overhead should be equivalent to using a raw pointer, since the Callback has to take a reference either way. Glancing through bind_helpers.h, I see a partial specialization for scoped_refptr that avoids doing any unnecessary AddRef/RemoveRef when a scoped_refptr is used.
With a raw pointer, only the bind state holds a ref. With scoped_refptr<T>, an additional
>
> Is it true that passing scoped_refptr by const-ref is discouraged (officially or by consensus)? If so, what's the reasoning?
It looks the discussion was at https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/9e83addf85d2b445/56905ed52bcc70e9?lnk=gst
>>>>>> Chromium Developers mailing list: chromium-dev@chromium.org
>>>>>> View archives, change email options, or unsubscribe:
>>>>>> http://groups.google.com/a/chromium.org/group/chromium-dev
>>>>>
>>>>>
>>>>> --
>>>>> Chromium Developers mailing list: chromium-dev@chromium.org
Argh, the first inline comment should read:
Right, that's why I think we should consider allowing it if we remove the implicit conversion.
(Sorry for the spam)
Daniel
Argh, the first inline comment should read:
Right, that's why I think we should consider allowing it if we remove the implicit conversion.
(Sorry for the spam)
Daniel
On Jan 18, 2012 8:21 AM, "Daniel Cheng" <dch...@chromium.org> wrote:
On Jan 18, 2012 8:08 AM, "David Michael" <dmichael@chromium.org> wrote:
>
> On Tue, Jan 17, 2012 at 7:10 PM, Albert J. Wong (王重傑) <ajwong@chromium.org> wrote:
>>
>> On Tue, Jan 17, 2012 at 6:06 PM, Daniel Cheng <dcheng@chromium.org> wrote:
>>>
>>> It's probably not a huge cost. However, the proposed change would make it impossible to avoid the extra AddRef/Release--from what I remember, example 3 is currently discouraged/banned for being too subtle. It'd be nice to make this change while still allowing people to easily avoid refcount churn if they wanted, whether it involves allowing example 3 or adding move semantics.
>>
>>
>> Huh...I didn't know example 3 was discouraged. For the record, it works completely correctly. The Callback object owns the actual ref-pointer, and the function invocation only gets a const-reference to it.
>
> ...and the reference counting overhead should be equivalent to using a raw pointer, since the Callback has to take a reference either way. Glancing through bind_helpers.h, I see a partial specialization for scoped_refptr that avoids doing any unnecessary AddRef/RemoveRef when a scoped_refptr is used.With a raw pointer, only the bind state holds a ref. With scoped_refptr<T>, an additional
>
> Is it true that passing scoped_refptr by const-ref is discouraged (officially or by consensus)? If so, what's the reasoning?It looks the discussion was at https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/9e83addf85d2b445/56905ed52bcc70e9?lnk=gst
Can you clarify what you're asking for? Do you want Bind to allow you to send raw pointers when scoped_refptrs are expected by the bound method, and/or vice-versa? That should be possible, though it still carries some risk that it will be too easy to mix and match and make a mistake. I think it should be acceptable to force developers to either call .get() or wrap their raw pointer in a scoped_ptr. Having the compiler complain about it if you forget at least makes you have to stop and think about what you're doing.