3 ms·
So I used to think this, but I've come around a bit. What indexes do is let you put a pointer "to sleep"; it can be woken up only by pairing it with a live dat
by ryani 8y ago
So I used to think this, but I've come around a bit. What indexes do is let you put a pointer "to sleep"; it can be woken up only by pairing it with a live data structure which you correctly have safe ownership of at the time. This "dormant" pointer can be safely stored in data structures that have no concept of the containing object's lifetime, which in games is exactly the common use of entity handles (usually implemented as generational indices), hibernating until the original object is really needed.
I think it's possible to write a DormantPtr library that encapsulates this pattern with better ergonomics than vec<> + generational index.
- pas 8y agoKind of like a WeakRef in Java?