Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-12-21 14:17:01


From: "Peter Dimov" <pdimov_at_[hidden]>

> From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> > On second thought, this conclusion leads me back to my original proposal:
> > use the technique of grin_ptr<> with
> > scoped_ptr<>.
> >
> > It doesn't make sense to change scoped_ptr<> though,
>
> [...]
>
> On second thought, this actually makes sense to me. Scoped_ptr requirements
> will change slightly, in that it will require a complete type only when its
> constructor is instantiated.
>
> sizeof(scoped_ptr) will increase, but since scoped_ptr is noncopyable, this
> will not have much impact (it's not meant to be put in containers.)

Not so fast. Containers don't directly contain scoped_ptrs, but they can contain them indirectly (e.g. contain pointers to objects that house them). It is not uncommon to have lots of a smallish, noncopyable class that would use scoped_ptr. Even given heap overhead, increasing the size of scoped_ptr can make a big difference in overall memory used.

Consider a specific use case for scoped_ptr: When you have a class that needs an object only during certain times in its life. That object is created and destroyed as needed, managed by the class using a scoped_ptr. The whole point here is to keep memory allocation low when the object does not exist - a purpose that a big scoped_ptr would defeat.

Scoped_ptr is a basic, foundational class. I can't think of a class for which it is more important to only pay for what you need.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk