1

Is there any way to change vector memory allocation strategy? using your own strategy instead of doubling vector size on resize.

(here a good explanation about memory allocation)

abdolahS
  • 663
  • 12
  • 35

2 Answers2

2

No. There is no standard way to affect the growth strategy of std::vector.

At least, there is no guaranteed way to reduce the growth rate. You can use reserve before the growth triggering element addition which effectively allows you to control the lower bound of the growth rate.

instead of doubling vector size on resize

That's not necessarily the strategy used by the vector implementation.

eerorika
  • 232,697
  • 12
  • 197
  • 326
1

As far as I know, changing vector memory increasing strategy is not allowed in c++ unless you implement a vector yourself.

If you do want to control vector memory increasing strategy, you can use reserve.

zhvala
  • 118
  • 5