3 ms·
I don't see any reason why you couldn't have a Rust ECS that keeps track of the number of outstanding references to each entity and doesn't free them while ther
by pcwalton 8y ago
I don't see any reason why you couldn't have a Rust ECS that keeps track of the number of outstanding references to each entity and doesn't free them while there are any references left. You'd have an opaque "reference" object instead of an index. (Care would have to be taken to make sure the references can't go dangling when the vector is resized, but it should be possible.)
But usually programmers intend to destroy entities in one place; for example, in UI code, a programmer typically expects a widget to be destroyed once it's removed from the window. It can be beneficial to have the runtime system diagnose if a reference to an object thought to be destroyed is actually used. So I haven't seen anyone actually go to the trouble…
- int_19h 8y agoAt this point you're basically writing a garbage collector. Which you might as well do with raw pointers, if it's a part of the language, and it will be more efficient.