Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"live C++ objects that live in memory mapped files"?

So I read this interview with John Carmack in Gamasutra, in which he talks about what he calls "live C++ objects that live in memory mapped files". Here are some quotes:

JC: Yeah. And I actually get multiple benefits out of it in that... The last iOS Rage project, we shipped with some new technology that's using some clever stuff to make live C++ objects that live in memory mapped files, backed by the flash file system on here, which is how I want to structure all our future work on PCs.

...

My marching orders to myself here are, I want game loads of two seconds on our PC platform, so we can iterate that much faster. And right now, even with solid state drives, you're dominated by all the things that you do at loading times, so it takes this different discipline to be able to say "Everything is going to be decimated and used in relative addresses," so you just say, "Map the file, all my resources are right there, and it's done in 15 milliseconds."

(Full interview can be found here)

Does anybody have any idea what Carmack is talking about and how you would set up something like this? I've searched the web for a bit but I can't seem to find anything on this.

like image 833
Mart Avatar asked Aug 23 '11 10:08

Mart


People also ask

What is memory mapped C?

Memory-mapped files allow for multiple processes to share read-only access to a common file. As a straightforward example, the C standard library ( glibc.so ) is mapped into all processes running C programs.

Are memory mapped files thread safe?

Yes. If one thread changes part of the data in the mapping, then all other threads immediately see that change. You need to ensure the threads coordinate their changes so no thread is accessing an inconsistent view (eg.

Why are memory mapped files used in games?

Benefits of Memory Mapped Files Accessing RAM is faster than disk I/O operation and hence a performance boost is achieved when dealing with extremely large files. Memory mapped files also offer lazy loading which equated to using a small amount of RAM for even a large file.


2 Answers

The idea is that you have all or part of your program state serialized into a file at all times by accessing that file via memory mapping. This will require you not having usual pointers because pointers are only valid while your process lasts. Instead you have to store offsets from the mapping start so that when you restart the program and remap the file you can continue working with it. The advantage of this scheme is that you don't have separate serialization which means you don't have extra code for that and you don't need to save all the state at once - instead your (all or most of) program state is backed by the file at all times.

like image 65
sharptooth Avatar answered Nov 15 '22 17:11

sharptooth


You'd use placement new, either directly or via custom allocators.

Look at EASTL for an implementation of (subset) STL that is specifically geared to working well with custom allocation schemes (such as required for games running on embedded systems or game consoles).

A free subset of EASTL is here:

  • http://gpl.ea.com/
  • a clone at https://github.com/paulhodge/EASTL
like image 22
sehe Avatar answered Nov 15 '22 17:11

sehe