Dynamically allocated arrays or std::vector

前端 未结 10 2157
日久生厌
日久生厌 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:35

    The issue seems to be that you compiled your code with optimizations turned off. On my machine, OS X 10.5.7 with g++ 4.0.1 I actually see that the vector is faster than primitive arrays by a factor of 2.5.

    With gcc try to pass -O2 to the compiler and see if there's any improvement.

提交回复
热议问题