Thoughts on memory allocation...
Phil Edwards
phil@jaj.com
Fri Jun 28 15:10:00 GMT 2002
I see the problem. This paragraph:
> >>- There seems to something "missing" in the __allocator<> code since I
> >>had to add the operator == and != in order to get basic_string<> to
> >>compile, this does however not happen if I try to compile with
> >>malloc_allocator which is part of stl_alloc.h - why I don't know...
is misleading. There's nothing wrong with __allocator. It simply compares
the underlying allocators. You must define == for your own allocator
types, but you don't need to do anything with __allocator, because it will
automatically use the == that you define.
The predefined allocators -- i.e., the ones that we define for you in
stl_alloc.h, such as __malloc_alloc_template -- all have == defined for them.
> ...I guess that the only thing needed really is a comment that if you
> "roll your own allocator" and wrap that through __allocator<> you need
> to define your own operator == and != (see my header file) - however I
> don't know if this is by design?
Clause 20.1 of the standard lists the things that an allocator needs
to define.
Table 32 suggests that you don't actually need to have != defined, since
it can be defined as !(a == b), and I'm inclined to make that change in
the sources...
> I am running gcc3.1 so i guess thats the 3.0.97 code...
Actually, it's the 3.1 code. There were changes after 3.0.97. There won't
be many differences between 3.1 and 3.2 as far as allocators go.
Phil
--
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace. We seek
not your counsel, nor your arms. Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen. - Samuel Adams
More information about the Libstdc++
mailing list