Boost logo

Boost Users :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2005-05-23 19:22:26


On May 23, 2005, at 6:13 PM, Caleb Epstein wrote:

> On 5/23/05, Sohail Somani <s.somani_at_[hidden]> wrote:
>>> -----Original Message-----
>>> Because that would make it larger than sizeof (T*). I
>>> believe the general consensus on this is to use shared_ptr or
>>> perhaps the upcoming policy_ptr.
>>
>> For educational purposes, why is this important?
>
> I'm not certain, but I would guess that overhead is the reason.
> Perhaps someone more closely involved in the implementation (Peter?)
> would care to comment.
>
> The "bells and whistles" all went into shared_ptr. Unless you're
> trying to eke out every last CPU cycle from your code, using
> shared_ptr as a scoped_ptr w/deleter is an eminently reasonable design
> choice

A customized deleter does not have to occupy space if it has no data
members. boost::compressed_pair can easily be used to optimize away
space for an empty member, e.g.:

compressed_pair<T*, D> ptr_; // space for D optimized away if D is
empty class

For my money, the best smart pointer in this domain (minimum overhead,
custom deleter) today is static_move_ptr:

http://www.kangaroologic.com/move_ptr/

I hope that C++0X will have a cleaner version of this by the name of
std::unique_ptr, but that is far from certain.

-Howard


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net