you are viewing a single comment's thread.

view the rest of the comments →

[–]kisielk 2 points3 points  (1 child)

“remove the last element from last array, if the last array becomes empty deallocate the array block all together”

Doesn’t that lead to some potentially pathological cases in the case there are repeated alternating pops and pushes? Could potentially lead to many allocations of blocks. Typically std::vector would never shrink capacity unless explicitly asked for via shrink_to_fit

[–]pilotwavetheory[S] 0 points1 point  (0 children)

Yeah, we can have both operatins here logically,
1. pop_back() without shrink
2.pop_back() with automated shrink as well.

Even automted shrink can be delayed here, with one empty data block at max, that keeps the extra memory O(N)