Library guidelines
Frerich Raabe
raabe at froglogic.com
Thu Mar 16 11:09:13 GMT 2006
On Thursday 16 March 2006 11:51, Thiago Macieira wrote:
> Frerich Raabe wrote:
> >Hm, I'm a bit surprised that this is the case. If you use
> > visibility=hidden when defining KMyClass::Private, it still gets
> > exported just like KMyClass?
>
> On Unix I can confirm that it gets a hidden visibility, but I am not sure
> on Windows. Someone will have to test.
Hm so if you can confirm that it gets hidden on Unix, and you don't know about
WIndows, you'd still scrap the original statement:
>By convention, the private class will be called Private and will be in
> the class definition.
Better not, I think. In dubio pro reo. :-)
> >static const char stringData[] = {
> > "message1\0",
> > "message2\0",
> > 0
> >};
>
> You mean without the commas there and the final zero.
Yes, of course.
> >static int stringDataOffsets[] = {
> > 0,
> > 9
> >};
> >
> >static const char *message( int no ) {
> > return stringData + stringDataOffsets[ no ];
> >}
> >
> >Then you don't have to relocate anything at all, and all data can
> > probably (I'm not sure, but I'd guess so) be put in non-writeable
> > (shareable) memory pages, yet you don't have a runtime cost as with
> > QList<QByteArray> or something else. I think moc does something like
> > that with Qt 4.x as well.
>
> Yes, that's what moc does.
>
> That's fine for generated code, but that's really hard to maintain in
> hand-written code. If you change one string, you have to update all
> offsets from there until the end.
I just counted (I hope I didn't miscount :-) the characters myself in this
example. In a real-world program you could also add up the string sizes using
sizeof() but I guess if you have many strings, then it looks a bit silly. It
deserves a comment. :-)
Oh, and one thing I just realized: I got a lot of this information from the
infamous 'How to write shared libraries' paper by the even more infamous
Ulrich Drepper. I think it would be a good idea to put a reference to
http://people.redhat.com/drepper/dsohowto.pdf somewhere, because 'Guideline'
papers which just seem to say "Do it like this and that!" without telling
about the reasons are pretty annoying. The leftist in me starts to growl.
--
Frerich Raabe - raabe at froglogic.com
www.froglogic.com - Qt consulting and add-ons
More information about the kde-core-devel
mailing list