Rust's drop-related functionality is strictly only for values created by Rust itself. Don't use it on a pointer from C.
To free the data behind the C pointer you should call a C function that does it, so that definitely the same C's allocator is used. If the pointer comes from C's malloc
, then Rust's libc::free
may work, except it's dangerous to do so if Windows DLLs are involved, since each DLL may have separate runtime.
Don't use unsafe set_len
. You can use a safe loop with push()
— it optimizes well.
You can cast *mut f64
to *mut [f64; 6]
if you know there are certainly 6 items there (or std::slice::from_raw_parts()
if the length was dynamic).
From there you can use .as_ref().unwrap()
to make it a reference, and then .to_owned()
or vec.extend(&arr)
to copy it to a Vec
.