This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Still improving! (Was: Re: [PATCH] Avoid strtok for thread safety)
On Wed, Nov 27, 2002 at 02:47:55PM -0600, Benjamin Kosnik wrote:
>
> >Some time ago, in private mail he alluded to some troubles with memory
> >leaks and static allocation of strings, which led him to resort to C
> >strings (std::strings were in fact used, in the first implementation!).
> >If you browse a bit the repository you will learn, I think, that this
> >happened exactly when Benjamin started to systematically fight memory
> >leaks with Valgrind.
>
> Before std::strings can be used, dealing with a persistent string or
> strings for "C" locales needs to be done. I couldn't figure out how to
> do this, so I switched. I posted about this on the libstdc++ list, and
> there were no other suggestions.
>
> For what's being done here, std::strings are probably overkill, IMHO.
> Reasonable people may differ, and do.
I'm not doctrinaire about std::string; they just solve a problem
that is messy to solve other ways. I don't understand what is meant
by a "persistent string". Usually that has something to do with saving
on disk or transmitting over a wire.
> If you're worried about exception-safety, you can always add try/catch
> blocks around these allocations.
The try/catch block would have to be around the whole constructor,
because they would all leak if an exception occurs in any part of it.
Nathan Myers
ncm-nospam@cantrip.org