Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-08-23 07:28:54


I have a question regarding shared_ptr implementation:

currently shared_ptr is implementated so, that it contains:

    T * px; // contained pointer
    detail::shared_count pn; // reference counter

I am interested to know philosophical thoughts why this kind of decision was made to implement the
shared_ptr class this way?

I assumed to save space which is consumed by such a pointer one could move T pointer (T*) to
shared_count class. All shared_ptr classes would contain only one instance or (may be better
pointer to counter):

    detail::shared_count* pn; // reference counter

and the approach to retrieve pointer would be:

pn->px //since px would be moved to pn

This would reduce the size of shared_ptr<T> to sizeof(detail::shared_count*) which is at least by
sizeof(detail::shared_count) smaller of may be more if alignment has to used.

Are there any arguments which prevent shared_ptr from such implementation scenario?

With Kind Regards,

Ovanes Markarian


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