8 ms·
>We are talking about allocating memory, in a system level language, and unless you are jumping through hops[sic], there is just no way to do that. To be fair,
by drbawb 10y ago
>We are talking about allocating memory, in a system level language, and unless you are jumping through hops[sic], there is just no way to do that.
To be fair, if you want to call malloc it is still just as accessible[1][2] as it is in C. If you search the Rust documentation for malloc `libc::malloc` is even the first result. If you were to use that on stable Rust the error message will even tell you to link your program to the libc published on crates.io (which is just adding a line in your Cargo.toml file.)
I'm not sure I'd call that jumping through hoops. I'd love if Rust provided easy access to its own allocator on the stable release channel; but I'm willing to wait for them to get it right, these things take time.[3]
[1]: https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc/fn.malloc.html https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc/f...
[2]: https://is.gd/cgkX2R https://is.gd/cgkX2R
[3]: https://github.com/pnkfelix/rfcs/blob/117e5fca0988a1b0c4b6e4de83b633f92b0c9c84/text/0000-kinds-of-allocators.md https://github.com/pnkfelix/rfcs/blob/117e5fca0988a1b0c4b6e4...
- Manishearth 10y agoAlso, most folks would use `Box` with `Box::into_raw` (also `Vec::with_capacity` for dynamically sized stuff, which works fine. RawVec is an implementation detail; Vec exposes most of what you need for dealing with raw memory.