View source code
Display the source code in rt/lifetime.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.

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 elemsize
);

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

NameDescription
newlength new .length
elemsize size of the element in the new array

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)