|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-27 08:10:33
From: "Beman Dawes" <bdawes_at_[hidden]>
> At 09:01 AM 12/26/2001, Peter Dimov wrote:
>
> >From: "Beman Dawes" <bdawes_at_[hidden]>
> >> At 02:58 PM 12/21/2001, Peter Dimov wrote:
> >>
> >> >Do you have a concrete example of a real-world project where
> increasing
> >> the
> >> >size of scoped_ptr from 4 to 8 makes a big difference?
> >>
> >> Commercial code I maintain is full of objects which contain only
> >> scoped_ptr<>'s.
> >
> >This doesn't really answer my question, does it.
>
> Sorry, I should have been more explicit.
>
> Yes, it does matter because doubling the size when there are a lot of
small
> objects is objectionable.
An empty scoped_ptr<> does double its size, but the memory footprint of an
initialized scoped_ptr<> is not 4, it's 4 + heap overhead + sizeof(contained
object), so increasing it by 4 isn't a twofold increase.
So "big" difference means high empty:initialized scoped_ptr<> ratio. Ed Brey
has provided an example of such a case; still, I find it uncommon.
> >> The whole point of scoped_ptr<> is simplicity. Don't make it more
> >> complicated; that's not what it is all about.
> >
> >Depends on how you measure simplicity. The specification doesn't become
> >more complicated. Anyway, I simply asked a question, that's all.
>
> I see what you mean about the spec. But still...
My line of thought is: let's suppose that we change the spec so that
std::scoped_ptr::~scoped_ptr<T> is required to do the right thing for an
incomplete T. (This doesn't add complexity, it simplifies both the spec and
client code.)
One possible way to accomplish this is by storing an extra pointer. Is it
adequate? Controversial question, and so far the consensus seems to be 'no.'
How would a compiler/library writer implement scoped_ptr, then? By making
"delete p" do the right thing when the type pointed by p is incomplete. (A
possible implementation strategy: call __incomplete_delete(p) in this case,
and automagically instantiate an appropriate __incomplete_delete in some
translation unit where the type is complete. The problem of automatic
instantiation and picking a translation unit is well known: vtable,
templates.)
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk