Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::list custom allocator issues

Thread Tools

std::list custom allocator issues

Posts: n/a

We have a list derived from std::list that has a custom allocator
derived from std::allocator. This was originally written using VC++
6.0 which required a workaround for the fact that 6.0 did not support
nested templates classes, so could not use the rebind struct.
Instead, a _Charalloc function was implemented.

Now that we are moving to VS 2005, this is no longer working so I need
to implement using the rebind struct. So I did this, and changed the
charalloc function to be a regular allocate function. But I am
running into problems, which I am thinking may be partly because the
allocator is taking two template parms. The template is declared as

template <class Ty, class _Node>
class CObjectPoolListAlloc : public std::allocator<Ty>

And I declared the rebind struct as follows:

template<class _Other>
struct rebind {
typedef CObjectPoolListAlloc<_Other, _Node> other;

And then I changed from using charalloc to an allocator declared as
_Node* allocate(size_type _N)

I am getting this error from the compiler:
error C2440: 'initializing' : cannot convert from
'std::_List_nod<_Ty,_Alloc>::_Node *' to
'std::_List_nod<_Ty,_Alloc>::_Node *'

Any thoughts?


Reply With Quote
Posts: n/a
I got past that part realizing I needed to return pointer, not
_Nodeptr, but now have a puzzling error. I am seeing the following

error C2664:
'CObjectPoolListAlloc<Ty,_Node>::CObjectPoolListAl loc(const
CObjectPoolListAlloc<Ty,_Node> &) throw()' : cannot convert parameter
1 from 'CObjectPoolListAlloc<Ty,_Node>' to 'const
CObjectPoolListAlloc<Ty,_Node> &'

And the error is actually being given within the STL list code here:
_List_ptr(_Alloc _Al)
: _List_nod<_Ty, _Alloc>(_Al), _Alptr(_Al)

Why on earth would it not be able to convert to a const ref? Note
that CObjectPoolListAlloc does not in fact define a copy constructor,
but defaults to the base class. This code compiled fine before the
upgrade and my attemp to implement Rebind. Please forgive me if this
is a stupid question.

Reply With Quote
Posts: n/a
Problem is solved, seems copy constructor is now required where it was
sufficient to use base class implementation in 6.0

So nevermind!

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
allocator alignment issues... Chris Thomasson C++ 1 08-22-2007 03:05 AM
custom allocator using templates Robert Frunzke C++ 4 01-29-2006 05:30 PM
Custom memory allocator - alignment Romeo Colacitti C Programming 4 03-07-2005 01:02 AM
Custom allocator sample code for vector Alex Vinokur C++ 16 08-16-2004 11:25 AM
Idea for custom thread-safe STL allocator? Brian Genisio C++ 12 01-15-2004 03:41 PM