Overhead to using std::vector?

前端 未结 7 1170
星月不相逢
星月不相逢 2021-02-13 04:09

I know that manual dynamic memory allocation is a bad idea in general, but is it sometimes a better solution than using, say, std::vector?

To give a crude e

7条回答
  •  逝去的感伤
    2021-02-13 04:49

    std::vector could be constructed with an size_type parameter that instantiate the vector with the specified number of elements and that does a single dynamic allocation (same as your array) and also you can use reserve to decrease the number of re-allocations over the usage time.

提交回复
热议问题