Array.reserve

Reserve enough memory from the allocator to store n elements. If the current capacity exceeds n nothing will happen. If n exceeds the current capacity, an attempt to expand the current array is made. If expand is successful, all the expanded elements are default initialized to T.init. If the expand fails a new buffer will be allocated, the old elements of the array will be copied and the new elements will be default initialized to T.init.

struct Array(T)
void
reserve
(
size_t n
)

Parameters

n size_t

a positive integer

Complexity: O(max(length, n)).

Examples

import std.algorithm.comparison : equal;

auto stuff = [1, 2, 3];
Array!int a;
a.reserve(stuff.length);
a ~= stuff;
assert(equal(a, stuff));

Meta