Report a bug
If you spot a problem with this page, click here to create a Bugzilla 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 using a local clone.

core.internal.array.utils

This module contains utility functions to help the implementation of the runtime hook
License:
Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)
enum auto isNoThrow(alias F);
Check if the function F is calleable in a nothrow scope.
Parameters:
F Function that does not take any parameters
Returns:
if the function is callable in a nothrow scope.
template isPostblitNoThrow(T)
Check if the type T's postblit is called in nothrow, if it exist
Parameters:
T Type to check
Returns:
if the postblit is callable in a nothrow scope, if it exist. if it does not exist, return true.
@trusted void[] __arrayAlloc(T)(size_t arrSize);
Allocate a memory block with appendable capabilities for array usage.
Parameters:
size_t arrSize size of the allocated array in bytes
Returns:
void[] matching requested size on success, null on failure.
pure nothrow size_t newCapacity(size_t newlength, size_t elemsize);
Given 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:
size_t newlength new .length
size_t elemsize size of the element in the new array
Returns:
new capacity for array