
please wait
std::vector<T> v;
it's a bit more complicated. First we have the size of the vector itself sizeof(v)
. The size occupied by the elements v.capacity() * sizeof(T)
so in total sizeof(v) + v.capacity() * sizeof(T)
. Dynamic allocations might have additional overhead but that is ignored here.
capacity()
itself returns the size of the allocated memory for its elements. So no need to multiply it with sizeof(T)
.capacity()
returns the number elements that the vector has allocated space for, so the multiplication is needed.