Re: Efficient use of C++ Strings: Request for Comments
shablool wrote:
Except, of course, when it doesn't. I believe, in fact,
that most implementations today do NOT use dynamic
allocation for short strings (g++ being the major
exception).
The question here would be, "what is short?".
Whatever the implementation decides it is to be. For
various technical reasons, the cut-off point will generally
be a power of two. I've seen 8, 16, and 32, I think, but it
really doesn't matter. The point is that you depending on
the application, you can't say that there will be an
additional allocation.
For the sake of the
argument, lets assume "short" means less then 20 characters. What
happen if your application deals with a lot of strings which are up to
100 characters long? You still end up with memory fragmentation...
Some of the string implementations use special pools to
avoid fragmentation. (It drives me nuts in my test suites,
because without special precautions, they show up as memory
leaks:-).)
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]