[SOLVED] QVector vs c++ array - performance



  • 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!


  • Lifetime Qt Champion

    Hi,

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


  • Moderators

    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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.