I know that in std::vector, the size will grow every time it runs out of room. Yet I'm not noticing a pattern in how it grows. Can someone please explain to me the pattern and why it was chosen.
#include <iostream>
using namespace std;
#include <iostream>
#include <vector>
int main()
{
vector<int> myVector;
for(int i =0 ; i < 100; ++i)
{
myVector.push_back(i);
cout << myVector.capacity();
cout << ", ";
}
}
Result:
1, 2, 3, 4, 6, 6, 9, 9, 9, 13, 13, 13, 13, 19, 19, 19, 19, 19, 19, 28, 28, 28, 2
8, 28, 28, 28, 28, 28, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 6
3, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 6
3, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 9
4, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 141, 141, 141, 141, 141, 141