Array

Fast, mutable, resizable array implementation.

Constructors

this
this(size_t n = 0)

Constructs an Array and reserves space of n bytes.

Members

Functions

cap
size_t cap()

Returns the total capacity of the Array.

cap
void cap(size_t n)

Sets the capacity to exactly n bytes.

compact
void compact()

Compacts the capacity to the actual length of the Array. Destroys if the length is zero.

destroy
void destroy()

Frees the allocated memory.

elems
A elems()

Returns the Array as a dynamic array.

get
A get()

Returns a copy allocated using the GC and destroys this Array.

growcap
void growcap(size_t n = 0)

Grows the capacity by n or cap * 1.5.

len
size_t len()

Returns the size of the Array in bytes.

len
void len(size_t n)

Sets the size of the Array in bytes. Resizes space if necessary. Does not deallocate if n is zero.

opOpAssign
void opOpAssign(const X x)

Appends x of any type to the Array. Appends the elements if X is an array.

opSlice
E[] opSlice(size_t i, size_t j)
E[] opSlice()

Returns a slice into the Array. Warning: The memory may leak if not freed, or destroyed prematurely.

rem
size_t rem()

Returns the remaining space in bytes before a reallocation is needed.

rem
void rem(size_t n)

Sets the capacity so that n bytes of space remain.

reserve
void reserve(size_t n)

Allocates exactly n bytes. May shrink or extend in place if possible. Does not zero out memory. Destroys if n is zero.

shrinkby
void shrinkby(size_t n)

Shrinks the Array by n bytes.

Variables

cur
E* cur;

Points to the end of the contents. Only dereference if cur < end.

end
E* end;

Points to the end of the reserved space.

ptr
E* ptr;

Points to the start of the buffer.

Meta