Memory, Allocator<T> & __USE_MALLOC & alternatives

Phil Edwards phil@jaj.com
Tue Jun 11 16:18:00 GMT 2002


On Wed, Jun 12, 2002 at 11:05:48AM +1200, Tony Bryant wrote:
> The lack of an allocator specifier for std::string is the killer I think. I 
> don't suppose there's an ISO standard "std::stringwithallocator<ALLOC>" 
> template?

Given that std::string is just

    typedef basic_string<char>   string;

and basic_string has a default parameter for the allocator,

    template<typename _CharT,
             typename _Traits = char_traits<_CharT>,
             typename _Alloc = allocator<_CharT>
            > class basic_string;

you could write

typedef std::basic_string<char, char_traits<char>, allocator<char> >  MyString;

in your code, use MyString everywhere, and then go back and tweak the
third parameter as necessary.


std::priority_queue takes a (default) parameter specifying the underlying
container; it doesn't handle the memory itself.  The underlying container,
say, vector, takes an allocator parameter.


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