2 ms·
> 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, et
by arcticbull 7y 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.html https://doc.rust-lang.org/nightly/nightly-rustc/arena/index....
- steveklabnik 7y agoArenas exist in stable too, this is just the arena the compiler uses internally. See packages like https://crates.io/crates/generational-arena https://crates.io/crates/generational-arena or https://crates.io/crates/typed-arena https://crates.io/crates/typed-arena
- deleted 7y ago[deleted]
- arcticbull 7y agoAh of course, my bad, I must not have noticed. For some reason I read the "internal" flag as "nightly" :P
- steveklabnik 7y agoIt's all good!