So, I was looking for how a dynamic array works in general. I found two different concepts.
In c ++
In C ++, a dynamic array is usually implemented by vectors. Vectors set the capacitance to 0, increment the counter to insert a new element, and then double the size of the capacitance for new inserts.
vector.h
template <typename ValueType>
Vector<ValueType>::Vector() {
count = capacity = 0;
elements = NULL;
}
To expand the size of the vector
template <typename ValueType>
void Vector<ValueType>::expandCapacity() {
capacity = max(1, capacity * 2);
ValueType *array = new ValueType[capacity];
for (int i = 0; i < count; i++) {
array[i] = elements[i];
}
if (elements != NULL) delete[] elements;
elements = array;
}
In java
java arrayList, 10 ( JVM), , .
, , 10, , . , .
vector.h 0? (, 10) , 0, , - .
, , 10.
: - 0? , anyways , .