allocate
allocate fn(_ size: u64) -> ^void
Parameters
_ size: u64
Size in octets to allocate.
Return value
Return a pointer to the newly allocated memory. Since the pointer is ^void, it must be casted to a pointer of the correct type or turned into a slice with as before being used.
The memory must be freed when it is not needed anymore with the deallocate function to avoid memory leaks.
Usage
#start {
pointer: ^f32 = allocate(f32.size) as ^f32
deallocate(pointer)
length: u32 = 10
buffer: []u16 = allocate(u32.size * length) as ^u32 (..length)
deallocate(buffer)
}
See also
deallocate to free the allocated memory.