Library guidelines

Lubos Lunak l.lunak at suse.cz
Thu Mar 16 13:24:48 GMT 2006


On Thursday 16 March 2006 10:52, Thiago Macieira wrote:
> In the "Static objects", I'd like to add:
> "Try to avoid creating static arrays of strings because they incur in
> extra relocation at load-time. Example of code to avoid:
>
> static const char *messages[] = {
>   "message1",
>   "message2",
>   0
> };
>
> This type of coding should be avoided if possible. The example above could
> be replaced by a list built at first use (in which case you could use a
> QList<QByteArray> too) or by a switch.
>
> However, it is preferred to use this practice if the alternative is code
> that is of difficult readability and/or maintenance."

 I disagree. The two added relative relocations in the example above are going 
to make absolutely no practical difference, not even two hundred of them 
would, and these techniques, including what Frerich references (be it from 
moc or from Drepper's paper), are IMHO just unnecessary complications for the 
average developer. Large data in libraries are relatively rare, and data 
should not be public API anyway, so it should be easily fixable later if it 
turns out to be a problem.

 If you want to say something about this, I suggest just limiting it to "Avoid 
large static data structures containing non-trivial data types (including 
pointers). If you need to do so, ask on a mailing first about possible 
performance implications." If there will be any performance implications, 
people with good knowledge of these things will take care of it. I also 
wouldn't want e.g. Phonon HOWTO to include an in-depth explanation of FFT.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/




More information about the kde-core-devel mailing list