pub fn alloc<T>(count: u64) -> raw_ptr Expand description
Allocates zeroed memory on the heap.
Additional Information
In the FuelVM, the heap begins at VM_MAX_RAM and grows downward.
The heap pointer($hp) always points to the first allocated byte.
Initially the heap will look like this:
▾$hp
... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
▴VM_MAX_RAM
After allocating with let ptr = alloc::<u64>(1):
▾$hp
... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
▴ptr ▴VM_MAX_RAM
After writing with sw(ptr, u64::max()):
▾$hp
... 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF |
▴ptr ▴VM_MAX_RAM
For more information, see the Fuel Spec for VM Initialization
and the VM Instruction Set for Memory Allocation.
Arguments
count: [u64] - The number ofsize_of<T>bytes to allocate onto the heap.
Returns
- [raw_ptr] - The pointer to the newly allocated memory.
Examples
use std::alloc::alloc;
fn foo() {
let ptr = alloc::<u64>(2);
assert(!ptr.is_null());
}