Results 1 to 3 of 3

Thread: QQueue:QList::QStack:QVector?

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QQueue:QList::QStack:QVector?

    Why does QQueue inherit from QList but QStack inherits from QVector? Is there any special reason? I mean, why can't it be the other way around or both QQueue and QStack inherit from one of QList or QVector?

    Thanks.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QQueue:QList::QStack:QVector?

    Because QQueue prepends items whereas QStack appends them. QVector performs worse than QList when it comes to prepending, hence the inheritance choice for QQueue. As for QStack, it would be possible to make it inherit from QList AFAIK but the Trolls probably know what they are doing and there's at list a single reason that motivate their choice : as QVector pre-allocates memory only at its end (contrary to QList) their is no wastage (remember : QStack never prepend on its own, though the coder can do it manually...)

    Hope this helps.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QQueue:QList::QStack:QVector?

    There is no reason to inherit QStack from QList, because it would waste resources (QList has some extra space ready for incoming data at the beginning of its data structure).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.