Function rt.lifetime.newCapacity
Given an array of length size
that needs to be expanded to newlength
,
compute a new capacity.
ulong newCapacity
(
ulong newlength,
ulong size
);
Better version by Dave Fladebo: This uses an inverse logorithmic algorithm to pre-allocate a bit more space for larger arrays. - Arrays smaller than PAGESIZE bytes are left as-is, so for the most common cases, memory allocation is 1 to 1. The small overhead added doesn't affect small array perf. (it's virtually the same as current). - Larger arrays have some space pre-allocated. - As the arrays grow, the relative pre-allocated space shrinks. - The logorithmic algorithm allocates relatively more space for mid-size arrays, making it very fast for medium arrays (for mid-to-large arrays, this turns out to be quite a bit faster than the equivalent realloc() code in C, on Linux at least. Small arrays are just as fast as GCC). - Perhaps most importantly, overall memory usage and stress on the GC is decreased significantly for demanding environments.
Parameters
Name | Description |
---|---|
newlength | new
|
size | old
|
Returns
new capacity for array
Authors
Walter Bright, Sean Kelly, Steven Schveighoffer
License
Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)