Function Vector.capacity

Returns the size of the storage space currently allocated for the Vector.

size_t capacity() const pure nothrow @nogc @property scope @trusted;

This capacity is not necessarily equal to the vector length. It can be equal or greater, with the extra space allowing the object to optimize its operations when new elements are added to the Vector.

Notice that this capacity does not suppose a limit on the length of the Vector. When this capacity is exhausted and more is needed, it is automatically expanded by the object (reallocating it storage space).

The capacity of a Vector can be altered any time the object is modified, even if this modification implies a reduction in size.

The capacity of a Vector can be explicitly altered by calling member reserve.

Examples

Vector!(int, 10) vec;
assert(vec.capacity == typeof(vec).minimalCapacity);

vec.reserve(vec.capacity * 2);
assert(vec.capacity > typeof(vec).minimalCapacity);