QList bad_alloc error
-
Hello
I need your help, I'm using an QList to which I want to append up to 860 million elements. So i worte this code to test it:
@QList<qint16> myData;
myData.reserve(860000000);
for(qint32 a=0;a<860000000;a++)
{
myData.append(a);
}
qDebug()<<(float)myData.size()/1e6<<"Million entries";@But my program crashes (at line 2) and it get an error std::bad_alloc.
So I tried the same with QVector:
@ QVector<qint16> myData;
myData.reserve(860000000);
for(qint32 a=0;a<860000000;a++)
{
myData.append(a);
}
qDebug()<<(float)myData.size()/1e6<<"Million entries";@And I get the output from qDebug(): 860 Million entries.
Can someone tell me why this works with QVector, but fails with QList? And if there is a way I still can use the QList container?860Million entries times 16bit equals to approx 1.7GB, which should be no problem for my PC.
Why I want to use QList:
Later in my program I'd like to use this List as container for my data. And I want to insert smaller lists the size of 4e6 elements and what I've read so far is, that the QList is better for inserting elements, is that true or false? If the later I could stick to QVector and forget about QList...