Shouldn't stringstream ONLY use the allocator object?
Nathan Myers
ncm@nospam.cantrip.org
Fri May 11 16:13:00 GMT 2001
On Tue, May 08, 2001 at 05:57:10PM +0200, Carlo Wood wrote:
> I did run into a very nasty bug of my own library when trying to
> port it to libstdc++. A problem that is caused by the fact that
> std::basic_stringstream<char, std::char_traits<char>, my_allocator>
> is calling operator new and delete directly, without using
> 'my_allocator'.
>
> My question is: shouldn't classes that take allocators *only* use
> those allocators to allocate memory? Or is the allocator object
> solely intended to allocate space for the buffer that stores the
> data being written to it? This is not clear to me when reading
> the standard.
Of course stringstream is a special case, because generally the
iostream components don't use allocators. Certainly stringstream
operations are allowed to use various other library facilities
(including locale) which take no allocator arguments. The question
is, therefore, not whether stringstream must do *all* allocations
using the allocator (it can't), but how much should it use it?
The answer has to be something like: if it's doing a string-like
operation, it should use the allocator; if it's doing an iostream-like
operation, it should use op new or something else. In practice
this probably means that it should use the allocator only for the
string buffer.
Nathan Myers
ncm at cantrip dot org
More information about the Libstdc++
mailing list