#Pointer type with unchecked shared mutability?
1 messages · Page 1 of 1 (latest)
@hallow star Why can't I? Memory safety is enforced for all those types via the language's GC
There are a ton of types in Rust's stdlib that "just" ignore the rules-- that's the whole point of half the containers in the stdlib.
can you explain how using garbage collection enforces memory safety
what scripting language are you using, anyway
it's my own
all garbage collection does is cleaning up objects when they're not used anymore
you will have to ensure memory safety some other way
how am i going to access invalid memory if there's no new/free because the GC handles it for me?
you could move a type
memory safety is much more than just not double freeing or use after free
data races, for example
ok can you please just go away no offense but you aren't answering my question and you're adding a lot of noise
you're also trying to peg me on semantics which i don't appreciate 🙂
thanks! if anyone else knows please answer
You're not going to get any useful advice from anyone without actually giving any information
but raw pointers and ussafecell are meant for exactly that thing
What you can't do is use raw pointers and unsafecell and then just ignoring the rules. It is up to you to enforce these rules yourself, that is what unsafe means
given that you have to ask this question there is zero chance you will be able to do this correctly, that is why I asked questions
and more to the point, you can often just avoid unsafe altogether and use types like cell/refcell/mutex etc
I said that you can't ignore the rules, which remains true
if you use unsafe, it's up to you to enforce them
lmao
they absolutely do not "ignore" the rules
they just use the rules in special ways to get new behavior
"the rules" are more complicated than just "shared xor mutable"
so shared mutability can work
if you're single-threaded then something like Cell (which never hands out references to the inner content) or RefCell (which checks it at runtime) can work
in a multithreaded context you want locks or atomics
you just have to make sure that data races do not happen and that you dont violate the aliasing rules (for example by mutating through a & except through a {ref,unsafe,}cell or to not have two overlapping &mut T used in overlapping ways)
Even in a single threaded context, violating the shared XOR mutable rules can be a terrible idea. Optimizers assume those rules are respected, and this is without getting into how, uh, Rust-style enums are fundamentally unsound if you ignore those rules.