Where is unstable feature heap_api now?

Hi

recently I'm reading rust nomicon, and following the example to create a Vec.

It used an unstable feature heap_api to allocate memory, but when I was trying it by myself, the code can't compile.

#![feature(alloc, heap_api)]

err msg: unknown feature `heap_api`

I'm using rust version with nightly-2019-07-19. So I guess it may be now stable or was moved to another feature. After searching I found no clue.

The rust pointer doc told me one of the ways to get a newly allocated mem is to get from c lib.

extern crate libc;

   unsafe {
        let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>()) as *mut i32;
   }

Is it the most recommended way to allocate mem in Rust?

Yes, I think all that is necesary to implement a Vec is stabilized in std::alloc module:

https://doc.rust-lang.org/std/alloc/index.html#functions

1 Like