[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Ulf Hermann ulf.hermann at theqtcompany.com
Mon Jul 13 13:26:03 CEST 2015


Mind that all this talk about QList being bad does *not* hold for primitively movable types of exactly sizeof(void *). For example QByteArray, which only consists of a single d-pointer. For those the disadvantages of QList against QVector don't manifest themselves, but the generated code is smaller. Consider the following simple program:

int main(int, char **)
{
     CONTAINER<QByteArray> horst;
     horst << "baum" << "baum";
     qDebug() << horst;
     return 0;
}

Replace CONTAINER with QVector, and I get a binary of 16kb, on my 64bit linux machine. Replace it with QList and I get 12kb:


ulf at zebra:~/dev$ ls -l build-untitled97-5_6-*
build-untitled97-5_6-Release:
total 68
-rw-r--r-- 1 ulf ulf 14568 Jul 13 13:17 main.o
-rw-r--r-- 1 ulf ulf 35953 Jul 13 13:17 Makefile
-rwxr-xr-x 1 ulf ulf 16016 Jul 13 13:17 untitled97


ulf at zebra:~/dev$ ls -l build-untitled97-5_6-*
build-untitled97-5_6-Release:
total 60
-rw-r--r-- 1 ulf ulf  8824 Jul 13 13:18 main.o
-rw-r--r-- 1 ulf ulf 35953 Jul 13 13:17 Makefile
-rwxr-xr-x 1 ulf ulf 12264 Jul 13 13:18 untitled97


-- 
Ulf Hermann, Software Engineer | The Qt Company

The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

Email: ulf.hermann at theqtcompany.com | Mobile: + 49 151 68964561 | Phone: +49 30 63 92 3255 www.qt.io |Qt Blog: http://blog.qt.digia.com/ | Twitter: @QtbyDigia, @Qtproject | Facebook: www.facebook.com/qt



More information about the Development mailing list