wasmedge_bindgen/lib.rs
1use std::mem;
2
3/// We hand over the the pointer to the allocated memory.
4/// Caller has to ensure that the memory gets freed again.
5#[no_mangle]
6pub unsafe extern fn allocate(size: i32) -> *const u8 {
7 let buffer = Vec::with_capacity(size as usize);
8
9 let buffer = mem::ManuallyDrop::new(buffer);
10 buffer.as_ptr() as *const u8
11}
12
13#[no_mangle]
14pub unsafe extern fn deallocate(pointer: *mut u8, size: i32) {
15 drop(Vec::from_raw_parts(pointer, size as usize, size as usize));
16}
17