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.capacity
This module contains support for controlling dynamic arrays' capacity and length
License:
Distributed under the
Boost Software License 1.0.
(See accompanying file LICENSE)
- pure nothrow @trusted size_t
_d_arraysetcapacityPureNothrow(T)(size_tnewcapacity, void[]*p, boolisshared); - Set the array capacity.If the array capacity isn't currently large enough to hold the requested capacity (in number of elements), then the array is resized/reallocated to the appropriate size. Pass in a requested capacity of 0 to get the current capacity.Parameters:
T the type of the elements in the array (this should be unqualified) size_t newcapacityrequested new capacity void[]* ppointer to array to set. Its length is left unchanged. bool issharedtrue if the underlying data is shared Returns:the number of elements that can actually be stored once the resizing is done - @trusted size_t
_d_arraysetlengthT(Tarr : T[], T)(return ref scope Tarrarr, size_tnewlength); - Resize a dynamic array by setting its .length property.Newly created elements are initialized based on their default value. If the array's elements initialize to 0, memory is zeroed out. Otherwise, elements are explicitly initialized. This function handles memory allocation, expansion, and initialization while maintaining array integrity.
void main() { int[] a = [1, 2]; a.length = 3; // Gets lowered to `_d_arraysetlengthT!(int)(a, 3, false)` }
Parameters:Tarr arrThe array to resize. size_t newlengthThe new value for the array's .length. Returns:The resized array with updated length and properly initialized elements.Throws:OutOfMemoryError if allocation fails.
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Wed Oct 1 13:16:40 2025