namespace sys.core
class DynamicBlock
Represents a simple dynamically allocated array. It is a continuous indexable memory block. The length of the array is always identical to its capacity, so any change in length will result in data reallocation: it does not support amortized growth and can't shrink without reallocating data.
Might become deprecated.
this{a: PtrSize};
this{copy: DynamicBlock};
this{move copy: DynamicBlock};
Creates a new array by either accepting the length of the new array and default constructing each element or by becoming a copy of an input array.
a | the length of the new array |
---|---|
copy | the source array to copy from |
this @allocate{len: PtrSize, capacity: PtrSize};
Standard pre-allocator slot implementation.
Due to the limitation of DynamicBlock having an equal `Length` and `Capacity`, the `capacity` parameter is treated as both.
len | the length of the new array. Ignored if not equal to capacity |
---|---|
capacity | the capacity of the new array |
def @attr(copy: DynamicBlock);
def @attr(move copy: DynamicBlock);
Standard assignment operators. Copy is a deep copy.
copy | the input data to be copied from |
---|
def ExpandTo(newLength: PtrSize);
def ExpandTo(newLength: PtrSize, init: T);
Reallocates the data to grow the block large enough to handle `newLength` items.
New items are default constructed or initialized to `item`.
newLength | the length to grow to |
---|---|
init | value of newly created elements |
def ExpandBy(delta: PtrSize);
def ExpandBy(delta: PtrSize, init: T);
Reallocates the data to grow the block large enough to handle `Length + delta` items.
New items are default constructed or initialized to `item`.
delta | the relative growth amount |
---|---|
init | value of newly created elements |
def ShrinkTo(newLength: PtrSize);
Reallocates the data to shrink the block to a size equal to `newLength` items.
Extra items are destroyed.
newLength | absolute length to shrink to |
---|
def ShrinkBy(delta: PtrSize);
Reallocates the data to shrink the block to a size equal to `Length - delta` items.
Extra items are destroyed.
delta | relative length to shrink by |
---|
def Fill(value: T);
Copies over all the elements in the dynamic array.
value | the value to initialize all elements with |
---|
def Clear();
Deallocates all data and set length to 0.
def Append(item: T);
def Append(item: T, count: PtrSize);
Append a single `item` once or `count`
item | item to append |
---|---|
count | number of times to append |
def SetLengthUnsafe(value: PtrSize);
Reallocates the array to a new length equal to `value` in an unsafe manner.
value | new length |
---|
def ExpandUnsafe(value: PtrSize);
Expands the array to a new length equal to `value` in an unsafe manner.
value | new length |
---|
def ShrinkUnsafe(value: PtrSize);
Shrinks the array to a new length equal to `value` in an unsafe manner.
value | new length |
---|
property @index: ref T; get;
Standard index operator into the dynamic array.
property Length: PtrSize
The length of the array. Same as `Capacity`.
property IsEmpty: Bool; get;
Returns true if the array has a `Length` greater than 0.
property Capacity: PtrSize
The capacity of the array. Same as `Length`.
property SysDataPointer: Ptr; get;
Returns an unsafe pointer to the memory block.