|
Boost Users : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2006-06-14 07:29:53
On Jun 14, 2006, at 4:56 AM, John Maddock wrote:
> Gottlob Frege wrote:
>>> if unknown_struct is an incomplete type (which is what I meant, and
>>> should have said), alignment_of doesn't compile.
>
> If the type is incomplete then you can't use aligned_storage
> anyway, since
> you don't know how much storage you'll need! Sorry but you've lost
> me now.
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".
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.
-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