arena allocators are cool. idea:

- mmap 1gb of virtual memory

- use this for for all game memory

- saving the *entire state* of your game is just a matter of the OS commiting dirty pages of your game memory to disk.

- close game, reopen. game instantly loads because of the previous game memory which is already in the OS page cache.

- amazing for playtesting: if players get stuck you can compress and send an entire snapshot of the memory game state to a dev and then dev can continue playing from their exact game state.

I wonder if any game engines do this.

this is similar to how nostrdb works when loading notedeck, which is why its so fast to load, but I only use that for DB memory and not everything.

Reply to this note

Please Login to reply.

Discussion

Are most games writing to disk for state?

serialized yeah, but that's not what I'm referring to here

🦀 what kind of game do you have in mind?

just taking a stab at making a game in rust on my weekends. not gonna say much about it except random excerpts like these

There's a tool on Linux that basically does this, and it works most of the time, it's called CRIU.

very cool!

We just trash collect and clean up generally. No need to clog up ram, but it depends on the platform.

I make games on Android so even with a lot of ram in newer devices, the allocation or many updates per frame can kill you quick.

Also would depend on what's being stored in memory too, physics, game objects, singletons etc

this is a bump allocator, it doesn’t really have any overhead. It’s just updating a number in a reserved contiguous array that exists for the entire duration of the app. Resetting the allocation per frame just sets the bump value to 0.

This is in the context of a non-gc language like rust or C, so it doesn’t apply to java/kotlin gamedev.

I use c# and unity

so yeah same thing

Sounds like a singleton of sorts? Usually set up for static variables you want to persist across scenes

I've written serialization/serialization code capable of doing this. Basically it used Rust's packed structure layout and some other tricks to make the in-memory representation serializable directly. So struct's, enums, etc. could be mmaped directly and safely.

Even pointers can be represented by just interpreting them as an offset from the beginning of the arena, and then either passing around the arena reference, or making it a global variable.

This on github somewhere?

I don't think so.