#[1, 2, 3]. If the latter only contains constants, it is compiled such that access to the byte array doesn't need the dynamic creation of the byte array. On many platforms this requires less memory. These literals are still mutable and will copy their content into memory the first time they are modified ("Copy on Write").
bytes := #[1, 2, 3]
bytes[0] = 22
print bytes // => [22, 2, 3]
bytes += #[4, 5]
print bytes // => [22, 2, 3, 4, 5]
bytes := ByteArray 4: it
print bytes // => [0, 1, 2, 3]
| constructor size/int --filler/int | Creates a new byte array of the given size. |
|---|---|
| constructor size/int --initial/int= | Creates a new byte array of the given size. |
| constructor size/int [initializer] | Creates a new byte array of the given size and initializes the elements using the provided initializer. |
0 <= from <= to <= size.list[from..to]. Since both arguments are optional (as they have default values), it is valid to omit from or to.
bytes := #[1, 2, 3, 4, 5]
sub := bytes[1..3] // A view into [2, 3]
sub[0] = 22
print bytes // => [1, 22, 3, 4, 5]
\uFFFD.