vector memory allocation strategy

后端 未结 3 1338
慢半拍i
慢半拍i 2020-12-03 22:08

i wrote a little piece of code to determine, how memory allocating in a vector is done.

#include 
#inc         


        
3条回答
  •  不知归路
    2020-12-03 22:18

    How the vector is growing is implementation defined. So different strategies can be used resulting in different capacity after inserting the same count of elements

    If you need to rely on how many items are allocated you should use reserve and/or resize methods of vector

提交回复
热议问题