Now I have an algorithm for dynamically allocating memory on an array:
TO answer your question:
It is true, C#'s List
implementation uses an internal array that is
IEnumerable
(which means it can be LINQ Queried, foreach
ed etc)and so on
Hence, I would ask you to use List
instead of your own List.
Oh and btw, if you want the source code of List
from Microsoft, then here it is
List.cs
EDIT
The source code of EnsureCapacity
in List
is:
// Ensures that the capacity of this list is at least the given minimum
// value. If the currect capacity of the list is less than min, the
// capacity is increased to twice the current capacity or to min,
// whichever is larger.
private void EnsureCapacity(int min) {
if (_items.Length < min) {
int newCapacity = _items.Length == 0? _defaultCapacity : _items.Length * 2;
if (newCapacity < min) newCapacity = min;
Capacity = newCapacity;
}
}