Handling of const strings/char arrays, e.g. with KActionCollection

Maksim Orlovich mo85 at cornell.edu
Tue Apr 22 18:32:31 BST 2008


> All actions are identified by a name, which is a QString in the API.
> If you grep through the KDE sources you see that almost everywhere instead
> plain C char arrays are used, e.g.
> 	actionCollection->addAction( "identifier" );
> Which will result in a deep copy due to the implicit QString(const char*),
> even if this is a static string and never to be changed.
> Payed with both runtime speed (on program start even) and heap memory (a
> KActionCollection stays e.g. for the complete life of a KMainWindow). No
> numbers/measurement if this is of practical relevance, but I am interested
> even theorethically.

Are any of those called in a loop? How many instances are there? By my
quick estimate (<100 actions, names <10 chars) You're talking about a
couple of kilobytes there at most. There are far easier ways to get rid of
more waste. I would suggest using a profiling tool.

> Question 1:
> Now I could go and wrap all strings with QLatin1String on the caller side.

That wouldn't do any good performance-wise since one would still need to
convert to UCS-2 for storage to a QString.

-Maks






More information about the kde-core-devel mailing list