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

Documentation for xyz.reserve() should clearly mention that existing data are preserved

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • Documentation
    • None
    • All
    • DaVinci 86, DaVinci 87, DaVinci 88

    Description

      Qt documentation should explicitly mention that QVector::reserve(), QByteArray::reserve() etc. preserve the existing data even when reallocating memory. The documentation is a contract between the library writers and users. If a thing is not written in the docs, it is (in theory) not binding. And I think this fact is so important it just should be binding and hence should be in the docs.

      I have seen some beginner's code (well... it was my very old code which I revisited ) where the programmer stored the array content to a temp variable, then reserved new size and then explicitly copied the data from the temp variable. All this because based on docs he was not aware that reserve preserves the existing data. So this copying of data was not necessary. It was a shameful piece of code and if the fact had been in the docs, the programmer would not have made this tragic mistake, which fortunately did not cause any bug but only harmed performance and his reputation.

      Attachments

        For Gerrit Dashboard: QTBUG-116062
        # Subject Branch Project Status CR V

        Activity

          People

            andreas.eliasson Andreas Eliasson
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change