3 ms·
> Having a raw pointer and having an index into an array are essentially equivalent You can split the handle (index) into an upper "magic" and lower "index" p
by pyjarrett 3y ago
> Having a raw pointer and having an index into an array are essentially equivalent
You can split the handle (index) into an upper "magic" and lower "index" part, with the handle being an opaque type, only being able to be accessed and modified by the container giving out handles. In C++, you'd likely see operator* and operator-> overloaded for usage. This technique is described in the original "Game Programming Gems" book.
Not 100%, but on usage, the handle checks the magic against what's currently in the data-structure to let you know if the handle has been freed and/or reused. Since handles are opaque, you can muck with the underlying objects as you want, e.g relocate them in memory, having multiple internal arrays, etc.