Using vector as a buffer without initializing it on resize()

前端 未结 5 868
执笔经年
执笔经年 2020-11-29 07:01

I want to use vector as a buffer. The interface is perfect for my needs, but there\'s a performance penalty when resizing it beyond its current size

5条回答
  •  渐次进展
    2020-11-29 07:55

    Encapsulate it.

    Initialise it to the maximum size (not reserve).

    Keep a reference to the iterator representing the end of the real size, as you put it.

    Use begin and real end, instead of end, for your algorithms.

提交回复
热议问题