Using arrays or std::vectors in C++, what's the performance gap?

后端 未结 19 1652
忘了有多久
忘了有多久 2020-11-22 03:23

In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustroup himself suggests not to use arrays. But are there significant perf

19条回答
  •  轮回少年
    2020-11-22 04:05

    If you're using vectors to represent multi-dimensional behavior, there is a performance hit.

    Do 2d+ vectors cause a performance hit?

    The gist is that there's a small amount of overhead with each sub-vector having size information, and there will not necessarily be serialization of data (as there is with multi-dimensional c arrays). This lack of serialization can offer greater than micro optimization opportunities. If you're doing multi-dimensional arrays, it may be best to just extend std::vector and roll your own get/set/resize bits function.

提交回复
热议问题