14 ms·
Interesting, I actually didn't know this. Not a rust developer obviously. It does sound like the kind of factoid that should be super upfront though. Half the
by tpoacher 2y ago
Interesting, I actually didn't know this. Not a rust developer obviously.
It does sound like the kind of factoid that should be super upfront though. Half the "better than c" comments I see here always seem to hint about c memory leaks being the big problem that rust comes to fix. So if it's not that, I honestly don't know what is being referred to by memory safety in this context then.
- NobodyNada 2y ago"Memory safety" is referring to safety from null-pointer dereferences, use-after-frees, buffer overflows, data races, invalid pointer casts, etc. Safe Rust has no undefined behavior. Memory leaks are bad but they don't cause undefined behavior (your program might use more memory than it needs, but an attacker can't gain remote code execution from a memory leak). So Rust has tools (such as RAII) to help prevent accidental memory leaks, but it doesn't guarantee absolute freedom from memory leaks.
- deleted 2y ago[deleted]
- mplanchard 2y agoIt's fairly up front in this portion of "the book," which is the standard learning material for new Rust programmers: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
- mplanchard 2y agoRe: comments about relative safety to C, I don't know specifically what kind of comments you're talking about, but Rust's memory safety guarantees are: - No data races: it is impossible in safe Rust for two threads to simultaneously mutate memory without appropriate guards - No reads/writes from memory that is not owned/allocated - Any location in memory may only have a single mutable reference at a time (and any number of immutable references) Combined, you eliminate a large class of memory-related bugs, including use-after-frees, double frees, and buffer under/overflows.