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

QVector reallocates when appending another vector even when there is enough capacity

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 4.7.0, 4.8.2
    • None

    Description

      Consider the following test:

      QVector<float> empty;
      QVector<float> buf;
      buf.reserve(45);
      QVERIFY(buf.capacity() == 45);
      buf.append(2.5);
      buf.append(10.7);
      QVERIFY(buf.capacity() == 45);
      buf << empty;
      qDebug() << buf.capacity();
      QVERIFY(buf.capacity() == 45);
      

      In my mind this test should pass, but the QDebug prints a capacity of 2 and the test fails. It seems that QVector reallocates to the size of this vector plus the size of the appended vector even when there is sufficient capacity to hold the new elements.

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              outspokengolem Rod Cheater
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes