mirror of
https://github.com/penpot/penpot.git
synced 2025-05-15 03:56:38 +02:00
🎉 Refactor memory managemnt for color linear gradient stops
This commit is contained in:
parent
00ab9ad3f0
commit
a4cfaa542c
3 changed files with 74 additions and 14 deletions
17
render-wasm/src/mem.rs
Normal file
17
render-wasm/src/mem.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#[no_mangle]
|
||||
pub extern "C" fn alloc_bytes(len: usize) -> *mut u8 {
|
||||
// create a new mutable buffer with capacity `len`
|
||||
let mut buf: Vec<u8> = Vec::with_capacity(len);
|
||||
let ptr = buf.as_mut_ptr();
|
||||
// take ownership of the memory block and ensure the its destructor is not
|
||||
// called when the object goes out of scope at the end of the function
|
||||
std::mem::forget(buf);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn free(ptr: *mut u8, len: usize) {
|
||||
unsafe {
|
||||
let buf = Vec::<u8>::from_raw_parts(ptr, len, len);
|
||||
std::mem::forget(buf);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue