Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-33019

Documentation should mention the size limitation of container classes.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • None
    • 4.8.5, 5.1.0
    • Documentation
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              docteam Qt Documentation Team
              qtcomsupport Qt Support
              Votes:
              2 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes