mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
29 lines
540 B
TypeScript
29 lines
540 B
TypeScript
@global()
|
|
export class Array<T> {
|
|
|
|
private ptr: usize;
|
|
|
|
readonly capacity: i32;
|
|
length: i32;
|
|
|
|
constructor(capacity: i32 = 0) {
|
|
if (capacity < 0)
|
|
throw new RangeError("invalid array length");
|
|
this.capacity = this.length = capacity;
|
|
if (capacity > 0) {
|
|
this.ptr = Heap.allocate(<usize>capacity);
|
|
} else {
|
|
this.ptr = 0;
|
|
}
|
|
}
|
|
|
|
dispose(): void {
|
|
store<i64>(changetype<usize>(this), 0);
|
|
Heap.dispose(this.ptr);
|
|
this.ptr = 0;
|
|
Heap.dispose(changetype<usize>(this));
|
|
}
|
|
|
|
// TODO
|
|
}
|