|
Boost : |
From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-04-29 18:36:40
"David B. Held" <dheld_at_[hidden]> wrote in message
news:aakfs8$ug3$1_at_main.gmane.org...
> It may very well be that in the end, chained policies are
> philosophically superior. But I don't think that MI is necessarily
> as big a memory hog as once thought. I might add that bcc is
> known as one of the worst optimizers both in terms of speed and
> space. It may turn out that a policy mixer is an acceptable
> alternative to policy chaining.
I agree with David. My opinion is that we should design for the future;
implementations that pessimize MI are also those that will likely have
trouble with other modern features. It's best to learn from the past. If
past is of any relevance, look at the allocator mess, especially the type
passed when instantiating it. Also look at the rebind<U>::other abomination.
Clearly this whole issue cries for making the allocator a template template
parameter, but at that time the feature wasn't ready, so we got what we got.
Thus, I'd say, let's not remove one testis of SmartPtr from the very
beginning. Unless, as Dave says, a chained inheritance would be conceptually
superior, which I do believe is possible.
> 5. Andrei waffled on this one, so I'm not sure whether a change
> is warranted or not.
I forgot what that was, and I lost your message.
> 12. Andrei says there is a bug in his implementation of release()
> where he did not reinitialize the Ownership policy. If I knew how
> this should be fixed, I'd do it. Andrei, could you clarify?
Yes. The current definition is:
// Inside smart_ptr
friend inline void release(smart_ptr& sp, stored_type& p)
{
checking_policy::on_release(storage_policy::storage());
p = get_impl_ref(sp);
get_impl_ref(sp) = storage_policy::default_value();
}
As you can see, the value stored is "leaked" in p, and the storage is
reinitialized. However, the ownership policy is *not* reinitialized, which
means that, the case of some unusual reference counting scheme, it might
release something it shouldn't. I think the right implementation is:
friend inline void release(smart_ptr& sp, stored_type& p)
{
checking_policy::on_release(storage_policy::storage());
p = get_impl_ref(sp);
get_impl_ref(sp) = storage_policy::default_value();
ownership_policy& op = *this;
op = ownership_policy();
}
Now the ownership is properly cleared. I'm not 100% clear on whether this is
the most general way, but in principle it should be correct.
> 19. Andrei, could you tell me what "Igen" means? dictionary.com
> was of no help.
"Igen" means "Yes" in Hungarian :o).
Andrei
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk