On Tue, Dec 23, 2014 at 1:51 PM, L. David Baron <dba...@dbaron.org> wrote:

> On Tuesday 2014-12-23 13:14 -0800, Eric Rescorla wrote:
> > Just to be clear, is your problem the implicit conversion itself
> > or the reference count increment/decrement?
>
> The latter -- the problem is that there's an implicit conversion
> that has surprising side-effects.
>
> (It sounds from this discussion like you've written a bunch of code
> that you wrote the way you did to avoid excess reference-counting,
> yet there may have been a bunch of excess reference-counting that
> you didn't know about.)


I could look, but I don't think so, for two reasons:

- I try to use UniquePtr<T> when I can, and for obvious reasons,
  UniquePtr<T> doesn't do implicit conversion.

- I generally don't do a lot of passing around of SmartPtr<Base>,
  just because the type of code I write tends not to have a lot of
  this kind of inheritance.

> On the specific topic of what users expect, what you expect may not
> > be what I expect, but I would observe that both C++11 shared_ptr
> > and Boost intrusive_ptr (the analog to our RefPtrs> automatically
> > convert from SmartPtr<Derived> to SmartPtr<Base> and appear to
> > increment the reference count in the same way that RefPtr does;
> > this seems to suggest that at least some people do expect it to
> > behave this way.
>
> Ugh.
>
> Then again, this wouldn't be the first thing in the standard library
> that didn't make sense for users who care about performance.


This may be a much longer argument, but I'm not convinced that
sacrificing what would otherwise be good programming practice
(never unboxing your pointers) at the altar of performance is a good
idea. I'd note that you only pay this penalty when you pass an object
of type RefPtr<Derived> to something that takes RefPtr<Base>,
and depending on your code, this may happen infrequently or
at least only happen a lot of times at a fairly small number of call
sites, which can then be optimized in the usual fashion by changing
to a raw pointer call.

-Ekr
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to