Function buffer

Dynamic circular array.

auto buffer(A) (
  A arg
);

<

Takes an advantage of the system's memory mirroring capabillities to create a memory loop so that memory copying wont be necessary once new data is concatenated. The buffer may be manipulated normally as if it were a T[] and can be implicitly converted to it. Buffer length after concatenation must be less or equal to the .max size of the array.

Parameters

NameDescription
arg The initiating data for the array. If it is immutable, it is copied into a mutable buffer. An empty buffer initiation can be achieved with the .init of any array type.

Returns

buffer!(Unqual!(ForeachType!A)[], false)

Examples

auto buf = buffer("Hello world!");
buffer!(char[], false) buf = "Hello world!";
buffer!(int[], false) buf = buffer([1,2,3,4,5]);
buffer!(ulong[], false) buf = buffer(cast(ulong[]) [1,2,3,4,5]);

Bugs

  • The ~= -operator cannot be used in @nogc code, but it does not use the GC.