#[unsafe(no_mangle)]pub extern "C" fn alloc(len: u32) -> *mut u8Expand description
Allocates a buffer of the specified length and returns a pointer to it.
This function allocates a buffer of len bytes using a Vec<u8> and returns a
mutable pointer to the allocated buffer. The Vec is created with a capacity of
len, and its ownership is immediately transferred to the caller through the
returned pointer. The allocated buffer must be deallocated using the dealloc
function to prevent memory leaks.
§Arguments
len- The length of the buffer to allocate, in bytes.
§Returns
A mutable pointer to the allocated buffer of the specified length.
§Safety
This function is marked as unsafe because it returns a raw pointer to memory,
and the caller is responsible for ensuring the proper deallocation of the buffer
to avoid memory leaks.
§Examples
use plugy_core::guest::dealloc;
use plugy_core::guest::alloc;
let len: u32 = 1024;
let buffer_ptr = alloc(len);
// Use the allocated buffer...
// Remember to deallocate the buffer when it's no longer needed.
unsafe { dealloc(buffer_ptr as u64) };