3 ms·
Don't you also know the type of the object when dealing with pointers and references (assuming no casts)? Though arenas are useful even outside of "hacks". In
by winwang 3y ago
Don't you also know the type of the object when dealing with pointers and references (assuming no casts)?
Though arenas are useful even outside of "hacks".
In the end, a pointer (or a reference, even) is "just" a usize index into the heap, which can be thought of as a heterogenous collection.
- db48x 3y agoYep. A pointer/reference is just an index into a giant shared mutable array of bytes, which is exactly what causes all of the problems :)
- IshKebab 3y agoNo. An invalid pointer can point to literally anything. Just because the pointer type says it points to T doesn't mean it really does. With an index into Vec<T> you are at least guaranteed that the object will be a T. You are guaranteed memory safety, but you aren't guaranteed to have a correct reference.