PDA

View Full Version : QQueue:QList::QStack:QVector?



jamadagni
20th August 2007, 11:25
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.

fullmetalcoder
20th August 2007, 11:30
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. :)

wysota
20th August 2007, 13:29
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).