newCapacity
fn
size_t newCapacity(size_t newlength, size_t elemsize) pure nothrowGiven an array of length size that needs to be expanded to newlength, compute a new capacity.
Better version by Dave Fladebo, enhanced by Steven Schveighoffer: This uses an inverse logorithmic algorithm to pre-allocate a bit more space for larger arrays.
- The maximum "extra" space is about 80% of the requested space. This is for
PAGE size and smaller.
- As the arrays grow, the relative pre-allocated space shrinks.
- Perhaps most importantly, overall memory usage and stress on the GC
is decreased significantly for demanding environments.
- The algorithm is tuned to avoid any division at runtime.
Parameters
newlength | new .length |
elemsize | size of the element in the new array |
Returns
new capacity for array