[Kstars-devel] Porting to Qt4: avoid pointers in QLists?

Jason Harris kstars at 30doradus.org
Mon Sep 12 05:15:36 CEST 2005


Hello,

On Saturday 10 September 2005 17:46, Jason Harris wrote:
> Another option I want to consider is to simply avoid pointers as QList
> members.  Then we don't need to worry about deleting list members.  I don't
> think performance will be impacted; QList still uses pointers internally,
> and the trolls claim that QList access is very fast.  In fact, the docs for
> QList claim that QList is usually faster than QVector, even though QVector
> guarantees that the items are stored at adjecent locations in memory.
>
Rather than speculate on the relative performance of QLists with pointers vs. 
QLists with objects, I just made a test program for it, which is attached if 
you'd like to try it out.  The program makes two QLists, the first containing 
SkyPoint objects, the second containing SkyPoint pointers.  It then populates 
each list with 36,000 members, and then performs EquatorialToHorizontal() on 
the members in each list.  

The program measures how long each operation (populating the lists, and 
looping through them for EquatorialToHorizontal()) takes.  A typical run 
looks like this:

Populating list 1
elapsed time: 50 ms
Populating list 2
elapsed time: 35 ms
Converting coordinates in list 1
elapsed time: 76 ms
Converting coordinates in list 2
elapsed time: 44 ms

So, it looks like QLists which contain pointers are slightly faster both to 
create and to access, despite what the Qt docs say.

I guess we'll keep using pointers in lists then.  Any other thoughts?

Jason

PS: if you try out the program, you have to modify the top two lines of the 
Makefile to point to your Qt4 and kdelibs-4 installation

-- 
KStars: KDE Planetarium
http://edu.kde.org/kstars
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qlisttest.tar.gz
Type: application/x-tgz
Size: 21666 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kstars-devel/attachments/20050912/c7725cab/qlisttest.tar-0001.bin


More information about the Kstars-devel mailing list