Object Soup is Made of Indexes (jacko.io)
from fettuccinecode@programming.dev to rust@programming.dev on 24 Oct 2023 11:34 +0000
https://programming.dev/post/4850038

#rust

beejjorgensen@lemmy.sdf.org on 24 Oct 2023 14:56 +0000 next

I like this approach for Rust in general when it comes to graphs. But it suffers from many of the same kinds of issues we get with pointers, e.g. dangling pointers, use after free, and so on. Tradeoffs!

Anders429@programming.dev on 24 Oct 2023 15:09 +0000 next

If you want to go one step further, a lot of game development uses a generational index, where the index is both a value and a generation, allowing you to know whether the index you currently have stored references an object that has already been destroyed and replaced by another object. Basically every ECS framework I’ve ever seen uses this pattern.

huntrss@feddit.de on 24 Oct 2023 18:28 +0000

Interesting. Can you provide a good link regarding generational index?

Anders429@programming.dev on 24 Oct 2023 21:29 +0000

I was originally introduced to the idea by this RustConf 2018 keynote: kyren.github.io/2018/09/14/rustconf-talk.html. It’s rather dense though.

I did find this random article that outlines just the concept of generational indices pretty concisely: …medium.com/generational-indices-guide-8e3c5f7fd5…

huntrss@feddit.de on 25 Oct 2023 08:55 +0000 next

Thanks

oconnor663@programming.dev on 02 Nov 2023 15:23 +0000

That same keynote is linked in the last paragraph! :) The slotmap crate is also one option for generational indexes.

Anders429@programming.dev on 02 Nov 2023 20:51 +0000

Ah, you’re right! Somehow I missed that, good catch.

EthicalAI@beehaw.org on 27 Oct 2023 17:10 +0000

This is exactly right and very educational