Reply to post: Re: Memory safety

Is it time to retire C and C++ for Rust in new programs?

karlnapf42

Re: Memory safety

> Memory safety isn't just about "corruption", "leaks" and so it;

You can leak memory in safe Rust: That is fine and not a safety issue at all.

> Does Rust allow memory allocation to be controlled in the same way as C++ does (user-provided allocators and the like)?

That is in the works still: Linus rightfully insisted that this is needed to use Rust in the kernel. Usually Rust will panic when running out of memory.

> A lot of safety systems prohibit the use of dynamic memory

Rust comes with three standard libraries: Core, alloc an the std nowadays. Core holds all the core stuff and does not allocate memory ever. The alloc crate adds memeory allocation and data structures that need that. The actual standard library (which core and alloc were split out of) is basically a combination of those two plus a few extras.

It is perfectly possible to write code using core only -- that is widely used in embedded development. There is a ever growing library eco-system that is "no-std" and avoids alloc or allows to opt out of alloc use.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon