Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-06-14 10:22:08


Howard Hinnant <hinnant_at_[hidden]> writes:

> There are applications such as boost::function where aligned storage
> for an unknown type is useful. In boost::function's case, aligned
> storage could be used to implement the "short string optimization".

And so it is, AFAIK.

> The general pattern is:
>
> class Container
> {
> private:
> const unsigned buf_size = ...;
> aligned_storage<buf_size>::type buffer;
> public:
> template <class T>
> Container(const T& t) {/* might stick t into buffer instead
> of on heap, based on sizeof(T) */}
> };
>
> On Jun 14, 2006, at 6:55 AM, David Abrahams wrote:
>
>> I think what the OP is looking for is called boost::shared_ptr ;-)
>
> shared_ptr can't compete with this application performance-wise.

Well, it depends how expensive it is to copy your small object. If it
turns out that T is a vector, and it fits in your local buffer, when
Container is copied it might be a lot cheaper to use shared_ptr.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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