| Mycroft Holmes 2005-04-29, 9:04 am |
| We managed to get a working allocator for map, but we experienced a
bizarre problem, and we are unsure if it's a problem in VC71 map or not.
we have a class, which efficiently manages a pool of blocks of memory of
known length. say:
template <size_t BLOCK_SIZE>
class block_pool
{
public:
void* get_block(int n); // get n contiguous blocks
void release_block(void*);
};
so we wrapped it in a custom allocator:
at the beginning, the class was written more or less like this:
template <typename T>
class block_allocator
{
typedef block_pool< sizeof(T) > storage_t;
static storage_t* pool_;
public:
// rebind, etc. etc.
};
template <>
class block_allocator<void>
{
// etc. etc.
};
compilation failed with bizarre error messages, because of a class in
<xtree> wcih contains the statements:
// ...
typedef typename allocator_type::template
rebind<_Node>::other::pointer _Genptr;
struct _Node
{
_Node(_Genptr _Larg, _Genptr _Parg, _Genptr _Rarg,
//...
compilation of _Node requires _Genptr, which in turn requires
rebind<_Node>::other, which is block_allocator<_Node>, which at the
moment is incomplete.
so storage_t cannot be defined, the typedef does not compile and the
compiler reports something like _Genptr is unknown.
Knowing that, it was easy to workaround: we modified the allocator and
took out all references to sizeof(T).
template <typename T>
struct arena
{
static block_pool<sizeof(T)>& instance()
{
static block_pool<sizeof(T)> p;
return p;
}
};
template <typename T>
class block_allocator
{
// ...
void deallocate(pointer ptr, size_type)
{
arena<T>::instance().release_block(ptr);
}
Now we wander: is this a limitation of current map implementation?
Is it a known problem? Is it documented in the standard?
Thanks in advance
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
|