Dynamically allocated arrays or std::vector

前端 未结 10 1883
日久生厌
日久生厌 2021-01-12 21:46

I\'m trying to optimize my C++ code. I\'ve searched the internet on using dynamically allocated C++ arrays vs using std::vector and have generally seen a recommendation in f

10条回答
  •  一生所求
    2021-01-12 22:48

    Your code provides an unfair comparison between the two cases since you're doing far more work in the vector test than the array test.

    With the vector, you're incrementing both the iterator (vecIT) and a separate variable (i) for generating the assignment values.

    With the array, you're only incrementing the variable i and using it for dual purpose.

提交回复
热议问题