
Howard Hinnant
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
::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