Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-01-16 16:25:43


Hello all,
I just wanted to get some opinions on the following static allocation
policy, revamped to ensure that there won't be alignment problems. Does
anything need to be revised?

    template < typename Type >
    class AllocateStatically
    {
    public:
        typedef Type * Pointer;

        static Pointer Create ( )
        {
            static Type instance;
            static bool first = true;

            if ( first )
            {
                first = false;
            }
            else
            {
                new ( reinterpret_cast < Pointer > ( &instance ) ) Type;
            }

            return &instance;
        }

        static void Destroy ( Pointer p )
        {
            p->~Type ( );
        }
    };

-Jason


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk