QString: Allocating more than needed?

David Leimbach kde-optimize@mail.kde.org
Sun, 26 Jan 2003 09:10:04 -0600


On Sunday, January 26, 2003, at 04:20 AM, Stefan Heimers wrote:

>
> There was a small discussion on the qt-interest Mailing list (two years
> ago) about how QString allocates more memory than needed, in order to
> avoid reallocation when growing the string.
>
> http://lists.trolltech.com/qt-interest/2001-03/msg00446.html
>
>
> - Does Qt still do this in the same manner?
>
> - Is there a way to create qstrings with a fixed length, which won't
> waste memory in case you know they will never grow?
>

QConstString will never grow... but I don't think you can ever change 
it either.

That may not be entirely true but to try to change it would rely on 
some undocumented behavior which is naughty :).

> - 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.
>

Use a QCString:
http://doc.trolltech.com/3.1/qcstring.html#length

its length function returns the same as strlen(data());

Sounds like what you want... it can also be resized.

>
> Stefan
> _______________________________________________
> Kde-optimize mailing list
> Kde-optimize@mail.kde.org
> http://mail.kde.org/mailman/listinfo/kde-optimize
>