F
Fred Zwarts
There are a few things I do not understand about the vector class
in de standard C++ library. The description of the resize member
function says:
void
resize(size_type sz);Alters the size of self. If the new size (sz) is greater than the current size, then sz-size() instances of the default value of type T are inserted at the end of the vector. If the new size is smaller than the current capacity, then the vector is truncated by erasing size()-sz elements off the end. If sz is equal to capacity then no action is taken.
Why does it compare the new size with both the current size and with the capacity?
I understood that the size and the capacity are different properties. If so, then this
description seems inconsistent to me.
Does this description mean that the capacity of a vector can be decreased by resize?
I understood that the capacity was never decreased in order to reduce the overhead
of allocating/deallocating dynamic memory.
Can somebody enlighten me?
F.Z.
in de standard C++ library. The description of the resize member
function says:
void
resize(size_type sz);Alters the size of self. If the new size (sz) is greater than the current size, then sz-size() instances of the default value of type T are inserted at the end of the vector. If the new size is smaller than the current capacity, then the vector is truncated by erasing size()-sz elements off the end. If sz is equal to capacity then no action is taken.
Why does it compare the new size with both the current size and with the capacity?
I understood that the size and the capacity are different properties. If so, then this
description seems inconsistent to me.
Does this description mean that the capacity of a vector can be decreased by resize?
I understood that the capacity was never decreased in order to reduce the overhead
of allocating/deallocating dynamic memory.
Can somebody enlighten me?
F.Z.