
custom container allocators and custom memory allocators
Quote:
>I have a custom memory allocator with handles for different memory
>pools. I can create a custom allocator template by simply starting
>with the Josuttis example code. But I do not see how to get our
>custom memory allocator with handles working with custom STL
>allocators - how do I get my handle information to the allocator so
>that the handle may be used in the calls in the template to the
>overridden operator new? I must be overlooking something simple...
Add the handle as a member variable of your custom allocator, and pass
it into the constructor. e.g.
explicit custom_allocator(handle_type h)
:m_h(h)
{
Quote:
}
bool operator==(custom_allocator const& other)
{
return m_h == other.m_h;
Quote:
}
//etc
Now, you can construct a vector like so:
HANDLE h = whatever;
std::list<int, custom_allocator<int> > l(
custom_allocator(h)
);
A well defined implementation will use the value of the allocator you
use to construct it. Be careful copying elements between containers,
etc, though.
Tom