PDA

View Full Version : Performance in functions with QList



john_god
31st July 2010, 02:46
Is there a significant performance issues between the next 2 functions ?



void cos(QList<Complexo> &x, QList<Complexo> &y)
{
y.clear();

for(int i=0;i < x.size(); i++)
{
y.append(cos(x[i]));
}
}

QList<Complexo> cos(QList<Complexo> & x)
{
QList<Complexo> y;

for(int i=0;i < x.size(); i++)
{
y.append(cos(x[i]));
}

return y;
}

The second seems more elegant but returning a large QList, will be slower ?

Lykurg
31st July 2010, 07:19
Go for the second variant. It is fast since QList is one of Qt's implicit data sharing class (In the docs under: Implicit Sharing). So only a pointer will be passed back and that is very fast:)

tbscope
31st July 2010, 07:22
If you're interested, here's some insight into QList:
http://marcmutz.wordpress.com/2010/07/29/sneak-preview-qlist-considered-harmful/

john_god
31st July 2010, 20:04
Thanks Lykurg and tbscope. Second variant shall be :cool: .
I checked MarcMutz link "QList considered harmful", didn´t know that. However there's some contradictions with Qt Nokia docs (http://doc.qt.nokia.com/qq/qq19-containers.html). Always thought QList was preferable to QVector. I have no experience with STL containers, never used them. So I'am sticking with QList, I like it's sintaxe better, and it suits my case.