|
|
|
|
|
by rslabbert
1635 days ago
|
|
For what it's worth, I find a lot of Zig code benefits from switching to u32/u64 indexes into an array instead of using pointers. This is only really doable if your container doesn't delete entries (you can tombstone them), but the immediate benefit is you don't have pointers which eliminates the use after free errors you mentioned. The other benefit is that you can start to use your ID across multiple containers to represent an entity that has data stored in multiple places. See [1] for a semi-popular blog post on this and [2] for a talk by Andrew Kelley (Zig creator) on how he's rebuilding the Zig compiler and it uses this technique. [1] https://floooh.github.io/2018/06/17/handles-vs-pointers.html
[2] https://media.handmade-seattle.com/practical-data-oriented-d... |
|