Re: do allocators have to be stateless?
william schilp wrote:
i want to pass a class to the allocator such that all STL allocators
draw from the same pool. BUT i do not want to use a global pool as we're
going multi-threaded and each thread will have it's own pool. so i'm
trying to pass the pool to the STL allocator as such:
class STLBlockAllocator {
public:
typedef T value_type;
... the rest of the typedef T stuff
inline BlockAllocator& getBlockAllocator(void) const
{
return(m_blockAllocator);
}
// constructor
STLBlockAllocator(BlockAllocator& blockAlloc) throw() :
m_blockAllocator(blockAlloc) {}
// copy constructor
STLBlockAllocator(const STLBlockAllocator & blockAlloc) throw() :
m_blockAllocator(blockAlloc.getBlockAllocator()) {}
You don't need that, since it does what the compiler generated one does
anyway.
template <class U> STLBlockAllocator
(const STLBlockAllocator<U>& t(STLBlockAllocator & blockAlloc))
throw() : m_blockAlloc(blockAlloc.getBlockAlloc()) {}
Should be:
template <class U> STLBlockAllocator
(const STLBlockAllocator<U>& blockAlloc)
throw() : m_blockAlloc(blockAlloc.getBlockAlloc()) {}
i'm using visual .net 2003 C++ v7.1
this compiles and works fine for vectors but for list the compiler fails
with the following error:
Right, lists need to rebind, vectors don't.
it appears that the rebind stuff is getting confused. for whatever
reason, the compiler appears to be trying to use the regular construtor
(blockalloc) constructor when it should be using the copy constructor (i
think).
Presumably you want to use your templated constructor, which isn't
strictly speaking a copy constructor.
or do i need some type of templated construtor that takes an
STLBlockAllocator<U> template as a parameter (and if so, what would that
look like??) anybody got any ideas how to fix this one??
It looks from your code that you already have such a constructor, but it
has an incorrect signature (for some reason it takes a function pointer
as its argument).
Tom