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. [SOLVED] QVector vs c++ array - performance

[SOLVED] QVector vs c++ array - performance

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.7k Views
  • 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.
  • M Offline
    M Offline
    maximus
    wrote on 21 Aug 2015, 09:28 last edited by maximus
    #1

    I am using a QVector<double> and wondering if there are major performance lost compared to a standard C++ array (double myArray[size])

    I am using QVector mainly because I like the use of the convenience functions (.fill, initialization with a value for the whole QVector). I could just create a function for the 2 things above that iterate in the C++ array and set the values. Is there any benefit from switching from QVector to a c++ array except less memory used?
    My QVector has a fixed size(40), and I do a lot of .replace() and .at()

    Thanks!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Aug 2015, 10:26 last edited by
      #2

      Hi,

      The only good answer is: benchmark
      Look what fits best to your use case/hardware setup

      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
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 21 Aug 2015, 10:59 last edited by
        #3

        Is there any benefit from switching from QVector to a c++ array except less memory used?

        QVector basically is an array with a couple of convenience methods around it so for most cases there's not gonna be any difference at all.
        It's only slightly larger (couple bytes) than a raw array so that's not a big issue either.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          maximus
          wrote on 21 Aug 2015, 11:32 last edited by
          #4

          Thanks SGaist and Chris for confirming this!
          Readable code > couple bytes, so I'm sticking with QVector.


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0

          1/4

          21 Aug 2015, 09:28

          • Login

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