Solved Problem in Qvector initialization
-
Hi
I face to amazing problem !!!
can any body say me the reason of this reaction ?
when I wrote first line code , and debug my code this line allocated 15GB RAM but when replace number of array with scientific symbol this problem solved and my app work regularly .//Qvector initialization 1- QVector <QByteArray> vector(200000000); // Replace number with scientific symbol 2- QVector <QByteArray> vector(2e8);
-
@Alexanov Interesting. Just tested on Windows 7: works and consumes only 12MB RAM. Are you sure it is not something else in your app?
What is your OS, compiler and Qt version? -
Check the size of the actual vector allocated in both cases.
qDebug() << "vector size " << vector.size();
The scientific representation is most likely not converted to the int number you are expecting.
-
Tried with Qt 5.8 on Win7 and:
MSVC 2013 x64
Both versions allocate the correct amount of memory:(200000000 * sizeof(QByteArray)) + sizeof(QVector<QByteArray>)
= (200000000*8)+8 = ~1.6GBMSVC 2013 x32
Both versions allocate the correct amount of memory:(200000000 * sizeof(QByteArray)) + sizeof(QVector<QByteArray>)
= (200000000*4)+4 = ~800MB@koahnig said in Problem in Qvector initialization:
qDebug() << "vector size " << vector.size();
use
capacity()
instead ofsize()
in this case.What compiler/OS/architecture are you using?
-
@jsulm ,@koahnig ,@VRonin
:)) Oh Sorry Thanks alot for your answers, I saw code again , my number had 9 zero in it not 8 zero.
2000000000 (2e9) not 200000000 (2e8)!
And RAM allocation for 2e9 is correct:
(200000000*8)+8 = ~16GB