Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

core.internal.array.capacity

This module contains support for controlling dynamic arrays' capacity and length
License:
Distributed under theBoost Software License 1.0. (See accompanying file LICENSE)

Sourcecore/internal/array/capacity.d

@trusted void_d_arrayshrinkfit(Tarr : T[], T)(Tarrarr, boolisshared);
Shrink the "allocated" length of an array to be the exact size of the array.
It doesn't matter what the current allocated length of the array is, theuser is telling the runtime that he knows what he is doing.
Parameters:
Tthe type of the elements in the array (this should be unqualified)
Tarrarrarray to shrink. Its.length is element length, not byte length, despitevoid type
boolissharedtrue if the underlying data is shared
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 enoughto hold the requested capacity (in number of elements), then the array isresized/reallocated to the appropriate size.
Pass in a requested capacity of 0 to get the current capacity.
Parameters:
Tthe type of the elements in the array (this should be unqualified)
size_tnewcapacityrequested new capacity
void[]*ppointer to array to set. Itslength is left unchanged.
boolissharedtrue 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 to0, 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:
TarrarrThe array to resize.
size_tnewlengthThe 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-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:06:18 2026

[8]ページ先頭

©2009-2026 Movatter.jp