Function String.reserve

Reserves size bytes for the string.

void reserve (
  const(ulong) size
) pure nothrow @nogc @trusted;

If size is less than or equal to the capacity, the function call does not cause a reallocation and the string capacity is not affected.

Parameters

NameDescription
size Desired size in bytes.

Example

String s;
assert(s.capacity == 0);

s.reserve(3);
assert(s.capacity == 3);

s.reserve(3);
assert(s.capacity == 3);

s.reserve(1);
assert(s.capacity == 3);