I am implementing my very own vector container in C++. To do so, firstly I am trying to fully understand how vectors work, and I've come across a problem while doing so.
According to C++ reference, vectors have both a size (the number of elements in the vector) and a capacity (the maximum amount of items the vector can store before reallocation is required). My first question is the following: when a vector is instanciated, how does the compiler ¨decide¨ the capacity of the vector? Is it a random number?
I have a second question as well. I have done several tests where I instanciate a vector with, let's say, X elements. In every single case, the capacity of the vector is X as well. However, if I pop back some elements, the size is reduced but the capacity remains the same. Does this always happen? I mean, are the capacity and size always the same when the vector is instanciated? If not, why do you think this is happening to me?
P.S. I compile with clang++