Overhead to using std::vector?

前端 未结 7 1163
星月不相逢
星月不相逢 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:45

    If you know the size in advance (especially at compile time), and don't need the dynamic re-sizing abilities of std::vector, then using something simpler is fine.

    However, that something should preferably be std::array if you have C++11, or something like boost::scoped_array otherwise.

    I doubt there'll be much efficiency gain unless it significantly reduces code size or something, but it's more expressive which is worthwhile anyway.

提交回复
热议问题