abdolahS
abdolahS

Reputation: 683

Change vector memory allocation strategy?

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)

Upvotes: 1

Views: 305

Answers (2)

eerorika
eerorika

Reputation: 238351

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.

Upvotes: 2

zhvala
zhvala

Reputation: 138

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.

Upvotes: 1

Related Questions