
Hi I've been testing out boost pool allocator, and my results shows it's slower than the STL allocator. I'm using VSNet 2005 SP1. See test code below. Also, on a separate issue, I notice the pool_allocator uses a singleton with static member in a function (Meyer's singleton). While this avoid the static construction issue, it does not free the memory until the application quits. This would work fine only POD data, if the dtor depends on a system in the application, it won't work. Shouldn't there be a pool allocator which can be used like the object_pool? Robin Test code -------- With boost pool, timing on average is (0.03) vs STL (0.02) seconds in release mode. In debug mode, its boost (0.99) vs STL (0.8) #include <boost/pool/pool_alloc.hpp> #include <iostream> #include <vector> using namespace std; class A { int x, y; public: A () : x (0), y (0) {} }; #include <windows.h> class Timer { public: Timer() { reset(); } /// reset() makes the timer start over counting from 0.0 seconds. void reset() { unsigned __int64 pf; QueryPerformanceFrequency( (LARGE_INTEGER *)&pf ); freq_ = 1.0 / (double)pf; QueryPerformanceCounter( (LARGE_INTEGER *)&baseTime_ ); } /// seconds() returns the number of seconds (to very high resolution) /// elapsed since the timer was last created or reset(). double seconds() { unsigned __int64 val; QueryPerformanceCounter( (LARGE_INTEGER *)&val ); return (val - baseTime_) * freq_; } /// seconds() returns the number of milliseconds (to very high resolution) /// elapsed since the timer was last created or reset(). double milliseconds() { return seconds() * 1000.0; } private: double freq_; unsigned __int64 baseTime_; }; int main () { Timer timer; for (int i = 0; i < 10; ++i) { // Switch allocators // typedef vector <A> VectorA; typedef vector <A, boost::pool_allocator <A> > VectorA; VectorA vectorA; double startTime = timer.seconds (); for (int jj = 0; jj < 1000000; ++jj) { vectorA.push_back (A()); } double endTime = timer.seconds (); cout << "Time taken is " << i << " - " << endTime - startTime << endl; } return 0; }
On 30/12/2007, Robin <al@cyberversion.com> wrote:
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
It seems your message got sent without any body text.