Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt vector reallocation during append()
Forum Updated to NodeBB v4.3 + New Features

qt vector reallocation during append()

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 398 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i was looking through qt vector append() source and i noticed that reallocation during insertion doesn't work alike std::vector. the latter allocates a new memory of size size * 1.5 while qt vector allocates a new memory of size + 1. why is this difference? also, this makes append linear, so what's the good?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That's a question better asked on the interest mailing list. You'll find there Qt's developers/maintainers. This is forum is more user oriented.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @user4592357 said in qt vector reallocation during append():

        while qt vector allocates a new memory of size + 1

        This is absolutely wrong. It just passes the new size to an internal function named realloc. What you miss is that the second parameter is set to QArrayData::Grow which will do the right thing.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        U 1 Reply Last reply
        5
        • Christian EhrlicherC Christian Ehrlicher

          @user4592357 said in qt vector reallocation during append():

          while qt vector allocates a new memory of size + 1

          This is absolutely wrong. It just passes the new size to an internal function named realloc. What you miss is that the second parameter is set to QArrayData::Grow which will do the right thing.

          U Offline
          U Offline
          user4592357
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          okay, so what's the size of the new vector, after re-allocation?

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #5

            @user4592357 said in qt vector reallocation during append():

            what's the size of the new vector

            The size is oldSize+1, the reseved size can be seen with capacity()

            /edit: simply following the calls you will get to this function: qCalculateGrowingBlockSize

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            6

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved