Interested in such a moment how much space does std :: vector int for 10x10 elements in x64 take?
for example, just std :: vector on 10 values ​​takes 24 bytes (the object itself) + 10x4 bytes (10 int values) = 64 bytes,
vector<int> a (10,1);
accordingly 10x10 elements will occupy 24 + 24x10 + 10x10x4 = 664 bytes or 24 + 10x10x4 = 424 bytes?
vector<vector <int>> и (10,vector <int> (10,1));
There was another question if I declared a vector
vector<vector <int>> b (10,vector <int> (10));
but filled only one of its elements with a number, for example
b[1][1] = 5;
the remaining elements of the second vector will occupy 4 bytes, or until I assign them a value, then only the vector structure takes place? Respectively, the size is 24 + 24x10 + 4 = 268, or in any case there will be 664 bytes?
std::vector
takes place both in the stack and in heap. According to the standard, it is guaranteed that it occupiesO(n)
memory in total, and I even think that n * sizeof (T) + O (1). But I think no one will give a guarantee for specific constants in O (1). - VladD