Hacker News new | ask | show | jobs
by arcticbull 2374 days ago
> As you said, malloc/free also have costs, and also GC has other benefits, like bump allocation, moving things to compact memory and improve cache locality, etc. 1ms pauses means GC is worth considering even for a game, in other words.

The general approach used by games is probably superior, which are arenas or zones.

One approach games use is to allocate everything that's necessary for a given frame in a single large block, carve it off over time as needed, then drop the entire arena. All allocations then have memory locality, no fragmentation, basically zero cost to allocate (increment a pointer) and zero cost to deallocate.

This kind of thing actually plays really nicely with Rust's lifetimes since you can couple frame lifetime with objects in that frame and get static validation. Arenas are already available in nightly [1].

[1] https://doc.rust-lang.org/nightly/nightly-rustc/arena/index....

1 comments

Arenas exist in stable too, this is just the arena the compiler uses internally. See packages like https://crates.io/crates/generational-arena or https://crates.io/crates/typed-arena
Ah of course, my bad, I must not have noticed. For some reason I read the "internal" flag as "nightly" :P
It's all good!