Re: What's the boost pool allocator good for?
On Jul 9, 3:11 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
I tested the speed of a simple program like this:
//------------------------------------------------------------
#include <list>
#include <boost/pool/pool_alloc.hpp>
int main()
{
typedef std::list<int> List_t; // default allocator
//typedef std::list<int, boost::pool_allocator<int> > List_t;
List_t l;
for(int i = 0; i < 100000; ++i)
l.push_back(i);
int counter = 0;
for(List_t::iterator iter = l.begin(); iter != l.end();)
if(++counter % 3 == 0)
iter = l.erase(iter);
else
++iter;
for(int i = 0; i < 100000; ++i)
l.push_back(i);}
//------------------------------------------------------------
Compiling this with "-O3 -march=pentium4" and running it in my
computer, the running time was approximately 33 milliseconds.
When I change to the version of the list which uses the boost
pool allocator and do the same thing, the running time is a
whopping 59 seconds. That's approximately 1800 times slower.
Did you expect anything different? The standard has been
carefully worded so that an implementation can optimize use of
the standard allocators, in a very container dependent fashion.
The purpose of the allocator parameter is not for a possible
optimization, but to support different semantics, and normally,
I would expect any custom allocator to be slower than the
standard allocator, at least if the library author has done a
good job.
What the heck is this pool allocator good for? At least not
for speed.
Isn't that question backwards? First, decide what you are
trying to achieve, and why the standard allocator isn't
acceptable. Then look for an allocator which achieves what you
need.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34