The flaw is that using a different allocator changes the type of container.
So vector with allocator A1 has different type than vector with allocator
A2. You cannot write non-templated function that works with vector
regardless of its allocator.
cheers,
Marcin
It is possible to write STL containers (including strings) that use
"polymorphic allocators" such that changing the allocator does not
change the type. See
http://www.lancediduck.com/papers/Cpp/StatefulSTL.pdf
I worked for a company recently that has an obsession with fixing this
"flaw" in standard container allocators--so much so that they actually
wrote their own version of the Standard libraries that "fixed" this.
And indeed, everyone could use std containers where you could pass in
a pointer to whatever allocator you dreamt up.
The resulting mess was beyond description, but suffice it to say that
those of us that actually had to build working scalable robust systems
quickly learned how to put the "change my type" allocators back in.
I hear over and over that the std allocator scheme is "broken"
"flawed" and such. And indeed it is hard to use. There are several
proposals for "improving" the allocators, two of which look promising
(N2035 and N1953). But often the fix is far worse than the problem.
In C++, by default, when you change the allocator (container or
otherwise) you change the type. This has been a feature of C++ since
Cfront 1.0. Using allocators that do not change the type is an option,
and this technique was use even in early C++. However, allocators that
know about the type of object they create allows many optimizations.
Java/C# use a form of the allocator that has O(1) heap allocations. C/C
++ typically use a system that has O(lg n) profile. This is why C/C++
will be at a disadvantage over Java/C# when making variable sized
objects such as vectors and strings, esp when using the default
allocator. But it is fairly easy (and seems to be a lost art) to make
a O(1) allocators in C++, as long as the allocator know about the type
of object being created. And you get to keep the destructors.
Lance