It pretty much is but with some fairly huge benefits:
* It's still memory safe (in the traditional sense). No chance of overwriting return addresses or whatever.
* It's type safe. There's no risk of type confusion. There's an excellent crate called `typed_index_collections` that lets you use a unique index type for each vector so the index is properly typed (i.e. you have `UserIndex` and `CommentIndex` or whatever and you can't mix them up).
* You don't need to do it for your entire program.
I have used this extensively in a profiler that worked on array oriented data structures. It worked great, especially because the data was immutable.
For mutable data it would probably work less well. I haven't tried that.
* You can choose to use handles smaller than a pointer.
* The NFA is cyclic, which makes memory management quite the chore. Even if you're using Rust's reference counted pointers. But if you use handles, the actual memory management becomes a lot simpler.
> * You can choose to use handles smaller than a pointer.
Did you measure any performance improvements due to using small handles?
I have a medium-sized project that uses a ton of `usize`s to reference elements in `Vec`s and would love to know if there's some potential for performance improvements there.
In this particular program I didn't do an in depth performance comparison because it wasn't really the point of the exercise.
But in the actual regex crate, I do indeed use `u32` as a representation for a handle. To a first approximation, it corresponds to about half as much memory usage.
* It's still memory safe (in the traditional sense). No chance of overwriting return addresses or whatever.
* It's type safe. There's no risk of type confusion. There's an excellent crate called `typed_index_collections` that lets you use a unique index type for each vector so the index is properly typed (i.e. you have `UserIndex` and `CommentIndex` or whatever and you can't mix them up).
* You don't need to do it for your entire program.
I have used this extensively in a profiler that worked on array oriented data structures. It worked great, especially because the data was immutable.
For mutable data it would probably work less well. I haven't tried that.