QString: Allocating more than needed?

Harri Porten kde-optimize@mail.kde.org
Sun, 26 Jan 2003 12:43:53 +0100 (CET)


On Sun, 26 Jan 2003, David Faure wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Sunday 26 January 2003 11:20, Stefan Heimers wrote:
> > - Is there a way to create qstrings with a fixed length, which won't 
> > waste memory in case you know they will never grow?
> 
> Yes, setLength().

Now please don't go around and add setLength() calls everywhere like

 QString s = "foo";
 s.setLength( 3 );

That won't pay off (and work) :)

> > - It would be nice to have an option to set the maximum expected length 
> > of a qstring, so it won't allocate in excess, or too little if you know 
> > a string will grow considerably.
> 
> setLength() ? :)

This latter is the intented and "good" usage.

Harri.