I'm trying to understand the way std::vector spatial complexity evolve after a call to reserve().
Here is the code :
vector<SparseData<T_Indices, T_Values>> v1 = vector<SparseData<T_Indices, T_Values>>();
v1.reserve(341);
vector<SparseData<T_Indices, T_Values>> v2 = vector<SparseData<T_Indices, T_Values>>();
v2.reserve(342);
With SparseData
containing 3 integers (4 Bytes each).
v1 cost is the theoritical cost O(v1) = 341*3*4 = 4092 Bytes
. Fine.
My problem is v2 cost. I expected O(v2) = 342*3*4 = 4104 Bytes
but the actual cost is 4151 Bytes
. There's a 47 Bytes
delta that I can't understand.
I'm measuring space using Visual Studio 2017 Community Diagnostic Tools (Snapshotting heap) which, I believe, is trustable.
What's the meaning of these 47 Bytes
? What do they possibly represent?
Thanks in advance.
Edit : I've edited the initial post so that classes names match with the screenshots. Below, the measured values for v1 (resp. v2) after a call to reserve(341) (resp. reserve(342)). Notice that two elements are not having same "values" than others. Also, v2 contains 345 SparseData
elements, giving an explanation for the first 4140 Bytes
: fine, this is the or greater part from the documentation :
If n is greater than the current vector capacity, the function causes the container to reallocate its storage increasing its capacity to n (or greater).
Still looking for the 11 Bytes
delta tho.