Re:Handles Are the Better Pointers
by throwawaymaths on Wednesday June 21, 2023 @12:52PM
(#36421052)
you'd be surprised how far you can get with this. Handles are basically how things like Erlang VM (and IIRC javascript VMs) work.
Re:Handles Are the Better Pointers
by meheleventyone on Wednesday June 21, 2023 @02:22PM
(#36422285)
Disagree, you can easily add validation to handle access with generations. The classic example in games is reusing pooled game elements where their lifetimes are very dependent on gameplay. For example reusing enemies from a pool of them where their lifetime is dependent on when they get spawned and destroyed which can be chaotic. Here handles with generations preserve memory safety by preventing access to stale data.
An arena assumes trivial ownership -- every object is owned by the arena.
But real world programs don't all have trivial ownership, e.g. a shell or a build system.
Probably the best use case for it is a high performance game, where many objects are scoped to either (1) level load time or (2) drawing a single frame. You basically have a few discrete kinds of lifetimes.
But most software is not like that. If you over-apply this pattern, you will have memory safety bugs.