Why do moest DUContext functions return a QVector and most DUChain use QList?

Hugo Parente Lima hugo.pl at gmail.com
Mon Oct 26 01:37:51 UTC 2009


On Sunday 25 October 2009 20:09:07 David Nolden wrote:
> Am Sonntag 25 Oktober 2009 23:00:46 schrieb Milian Wolff:
> > Hi there, especially David once again :)
> >
> > Could you elaborate why most of the DUContext methods return a QVector of
> >
> > pointers, and not a QList? To quote the documentation:
> > > For most purposes, QList is the right class to use. Operations like
> > > prepend() and insert() are usually faster than with QVector because of
> > > the way QList stores its items in memory (see Algorithmic Complexity
> > > for details), and its index-based API is more convenient than
> > > QLinkedList's iterator-based API. It also expands to less code in your
> > > executable.
> >
> > And (emphasise added)
> >
> > > If you want the items to occupy adjacent memory positions, or if your
> > > items are **larger than a pointer** and you want to avoid the overhead
> > > of allocating them on the heap individually at insertion time, then use
> > > QVector.
> >
> > There are lots of methods that return lists of pointers in a QVector. If
> > I read the docs, I'd say those should be QLists? Of course things like
> > importedParentContexts should stay the same.
> 
> A QVector is always faster and takes less memory than a QList, and since
>  the duchain handles very light-weight objects, that does count there.
> 
> In some places also QVector is used mainly because in the background the
>  data is saved in a QVector, so that the function can return a "const
>  QVector<...>&" instead of copying the object over.
> 
> QList is a "one fits all" container that is good for most usecases, but not
> when maximum performance is required. Ideally the whole duchain would not
>  use any of those high-level container classes at all.

If you don't need random access you could use QLinkedList, it's fast like 
QVector and have lower memory footprint[1].

[1] Unless your QVectors don't grow and known their exactly size at creation 
time.

> Greetings, DAvid
> 
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
> 

-- 
Hugo Parente Lima
"Precisamos de mais gênios humildes no mundo, hoje somos poucos!"
JID: hugo at jabber.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20091025/b48c0ecd/attachment.sig>


More information about the KDevelop-devel mailing list