Hi,

I've created a helper class called MemoryPooled to help add pooling to some of my classes; however, the performance seems slow by comparison to non-pooled behavior.  My code is shown below, I suspect I'm doing something wrong but I don't see how it can be my class.  Does anyone have any idea?

-Jason

// Begin code --------------------------------------
#include <Utilities/stopwatch.h>

#include <boost/pool/singleton_pool.hpp>
#include <boost/shared_ptr.hpp>

#include <iostream>

template<typename T>
class MemoryPooled : public T
{
public:
    MemoryPooled(){}
    virtual ~MemoryPooled(){}

    static const int countObjectsInitiallyAllocated = 1000;
    typedef boost::singleton_pool<T, countObjectsInitiallyAllocated> Pool;

    void* operator new(size_t /*p_memSize*/)
    { 
        return Pool::malloc();
    }

    void operator delete(void* p_memBlock)
    { 
        Pool::free(p_memBlock);
    }
};

struct Test1
{
   int i0; int i1; int i2; int i3; int i4;
   int i5; int i6; int i7; int i8; int i9;
};

void test(bool p_isPooled)
{
    Utilities::StopWatch sw; // Stopwatch is my helper for getting times
    sw.start();
    for(int i=0; i < 100000; ++i)
    {
        if( p_isPooled )
            boost::shared_ptr<Test1> item(new MemoryPooled<Test1>());
        else
            boost::shared_ptr<Test1> item(new Test1());
    }
    const double elapsed = sw.elapsedTime();
    cout << "Elapsed time: " << elapsed << " ms" << endl;
}

int main(int, char**)
{
    test(true);
    test(false);
}
// End code --------------------------------------

Output:
     Elapsed time: 106.812 ms (Pooled)
     Elapsed time: 94.2158 ms (Not Pooled)