The AssemblyScript Runtime
The runtime provides the functionality necessary to dynamically allocate and deallocate memory of objects, arrays and buffers, as well as keep track of references that are no longer used.
It is based on the TLSF memory manager and a pure reference counting garbage collector.
Interface
-
__rt_allocate(size:
usize
, id:u32
= 0):usize
Dynamically allocates a chunk of memory of at least the specified size and returns its address. Alignment is guaranteed to be 16 bytes to fit up to v128 values naturally. -
__rt_reallocate(ref:
usize
, size:usize
):usize
Dynamically changes the size of a chunk of memory, possibly moving it to a new address. -
__rt_free(ref:
usize
):void
Frees a dynamically allocated chunk of memory by its address. -
__rt_retain(ref:
usize
):void
Retains a reference. -
__rt_release(ref:
usize
):void
Releases a reference. -
__rt_collect():
void
Forces a full garbage collection cycle. -
__rt_typeinfo(id:
u32
):void
Obtains the runtime type information for objects of the kind represented by the specified id.
Stub
The fully functional yet minimal stub implementation provides dynamic memory allocation only but doesn't include sophisticated support to deallocate objects. Useful for prototyping or very short-lived programs with hardly any memory footprint.