2 ms·
> Then you can have dangling pointers that point to the wrong place. Generational indexes in a SlotMap or similar should rule this out. > Race conditions beco
by oconnor663 2y ago
> Then you can have dangling pointers that point to the wrong place.
Generational indexes in a SlotMap or similar should rule this out.
> Race conditions become possible.
How so?
> You need an allocator for the indices.
Yes, this usually becomes a central point of synchronization. (If you just have a SlotMap, you might not think of it as an "ID allocator", but that is half of what it is.) It doesn't have to be fully synchronous, though, and you can do fancy things with atomics.
> On rare occasions, it crashes with an invalid index.
Indexes become a sort of Weak pointer, and you get an Option when you dereference them, so you can certainly crash if you .unwrap() it or similar. You can use a Vec with "infallible" indexes if you don't want to support deletion, but if you do want to support deletion, the deleted case can bite you one way or another, no?
- Animats 2y ago> deleted case can bite you one way or another, no? Right. I use a renderer where, on rare occasions, that happens. I didn't write it, but now I have to fix it, because it's abandonware.