Details
-
Bug
-
Resolution: Done
-
P4: Low
-
None
-
4.8.5, 5.1.0
-
None
-
All
Description
QTBUG-6672 mentions, that the resize limit is INT_MAX/sizeof(T).
In the test application it is more like INT_MAX/(sizeof(T)+1) otherwise it is crashing with bad::alloc. Please check the test application.
On 64bit linux the resize limit is of QVector size is INT_MAX/(sizeof(T)+1) or memory limit, on 32bit it is the allowed 2gb memory or INT_MAX/(sizeof(T)+1) depending on the T.
Would be nice if the documentation mention this, because it is not obvious and if you search over the web this question has already been asked few times. Thanks!
#include <QVector> #include <QCoreApplication> #include <QDebug> class MyTestClass{ public: MyTestClass(){ } float m_float; int m_int; }; void test_resize_limit_class() { qDebug()<<__FUNCTION__; int size = INT_MAX/(sizeof(MyTestClass)+1); qDebug()<<size; QVector<MyTestClass> vector; vector.resize(size); } void test_resize_limit_char() { qDebug()<<__FUNCTION__; int size = INT_MAX/(sizeof(char)+1); qDebug()<<size; QVector<char> vector; vector.resize(size); } void test_resize_limit_float() { qDebug()<<__FUNCTION__; int size = INT_MAX/(sizeof(float)+1); qDebug()<<size; QVector<float> vector; vector.resize(size); } int main(int argc, char** argv) { QCoreApplication a(argc, argv); test_resize_limit_char(); test_resize_limit_float(); test_resize_limit_class(); return 0; }
Attachments
Issue Links
- relates to
-
QTBUG-86584 Update Qt Core Container Classes Overview page
- Closed
-
QTBUG-33037 Mention size limit of QByteArray in documentation.
- Closed