On Monday 17 October 2011 11:27:30 ext Robin Burchell wrote:
> On Mon, Oct 17, 2011 at 11:18 AM, André Pönitz <[email protected]>
> wrote:
> >> isn't QVarLengthArray what you're after?
> >
> > Except for the ugly name, a few missing convenience functions like
> > 'indexOf',
>
> well... yeah, i'm sure it could do with a better name, and some more
> convenience-of-use. point is, it's there now, even if it's not ideal
>
> > and the second template argument, sure ;-}
>
> you don't have to use that - at least off the top of my head, it has a
> default value.
[With impact on the ability to use forward declarations. But yes, this
is not really dramatic either.]
> > Given that QVector and QList cover the same ground in a lot of cases
> > and QVector is not heavily used in Qt API (compared to QList) tweaking
> > QVector seems to be the better choice from my perspective.
>
> If they were an internal implementation detail, I'd agree. given that
> you don't know how they are used outside of Qt, I don't think this is
> a safe assumption - I've seen (and written) rather a lot of code
> copying these around, and thus it's not something I'd personally want
> to do.
I have by now seen several ("numerical") projects initially using QVector also
for "main storage", only to replace it by "anything else" rather quickly.
So while it may not safe to assume that people do not use QVector, I'd say
it's a rather safe bet to assume that QVector is not used in critical code by
people who do measure performance and code size. And the others don't care
and/or won't notice.
Also note that dropping the implicit sharing does not necessarily translate
into "returning a QVector creates a deep copy". E.g. gcc applies RVO rather
aggressively, even at -O0.
Well, maybe the solution is really to make the QVarLengthArray interface
more "complete" and have the docs refer to it more often, so the typical
choice is not "QList vs QVector" but "QList vs QVarLengthArray". Ugly....
Andre'
PS: If you want to see something _really_ scary, run
#include <QVector>
QVector<int> bar()
{
QVector<int> c;
c.append(1);
return c;
}
through gcc -S (with either -O2 or -O0) and compare it to, say,
#include <vector>
std::vector<int> foo()
{
std::vector<int> c;
c.push_back(1);
return c;
}
_______________________________________________
Qt5-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback