[rust-dev] How to allocate record on memory?

Alexander Stavonin a.stavonin at gmail.com
Mon Apr 16 16:21:36 PDT 2012

It this the only way to create record in memory? May be someone has better

fn mk_mem_obj<T>() -> *T {
    libc::malloc(sys::size_of::<T>()) as *T

unsafe fn mk_mem_copy_of_obj<T>(src: T) -> *T {
    let size = sys::size_of::<T>();
    let dst = libc::malloc(size);
    libc::memcpy(dst, ptr::addr_of(src) as *libc::c_void, size);
    ret dst as *T;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120417/a8fdb586/attachment.html>

More information about the Rust-dev mailing list