I have some code which uses thousands of vectors each vector has only 4 entries, So I want to set the initial size of each vector to 4 so that I can optimize memory usage by not reserving unused memory.
I tried reserve method:
vector<Foo> bar;
bar.reserve(10);
but seems it expands and doesn't shrink, seems there also no constructor that creates a vector with a specified capacity.
Also 2 bonus questions:
What's the default initial capacity
Can I create a vector with a specific capacity?