You can use this class to check QVector::remove
performance:
#include <QDebug>
class Dummy
{
public:
Dummy()
{
qDebug() << "dummy ctor" << ++c1;
}
Dummy(const Dummy &d)
{
qDebug() << "dummy copy ctor" << ++c2;
}
Dummy &operator=(const Dummy &d)
{
qDebug() << "dummy asign" << ++c3;
}
static int c1, c2, c3;
};
int Dummy::c1 = 0;
int Dummy::c2 = 0;
int Dummy::c3 = 0;
The test itself:
int main(int argc, char *argv[])
{
QVector<Dummy> v;
for (int i = 0; i < 100; ++i)
{
v.append(Dummy());
}
qDebug() << "adding finished";
v.remove(0);
v.remove(v.size() - 1);
qDebug() << "end";
return 0;
}
In this example Dummy
assign operator is called 99 times when you remove the first element, and it's not called at all when you remove the last one.
Anyway, I suppose you have some design problems if you need to access container raw data. As JKSH said in comments, you can dynamically allocate memory for you data elements and then put those pointers into a container.