4 ms·
Currently I work as engineer in video games, and I would like to say that next step is just to write software completely without malloc+free and GC : you just a
by dmytroi 11y ago
Currently I work as engineer in video games, and I would like to say that next step is just to write software completely without malloc+free and GC : you just allocate virtual pages directly from OS, create your own pool allocators in them, and that it. When you need to "free" stuff you just wipe whole virtual page, O(1) free, faster then anything you could imagine. We have only three special cases : string operations (usually implemented with special string pool), heap (malloc + free) for libraries that cannot live without it, and everything else on stack.
That said, I honestly don't understand why everyone only talks about GC and malloc+free abstractions, because they simply do not materialize in physical world at all (even if malloc needs a new page, it will call kernel for it), cpu/kernel do not have such mechanisms, so this is only abstract limitation in developers heads. So why not just talk (if we actually end-up in situation when we need to talk about memory, 'cause usually it's just work) and measure about what's actually real?
- vvanders 11y agoVideo games end up being a special case where you tend to have somewhat discrete checkpoints and can dump large parts of RAM via pages. Still pooling is something that everyone should be taught and seems like very few are.
- viraptor 11y agoI'm not sure it's that special. At least the arena allocator approach. It's a great solution servers too. If the connections are short-lived, you can just give a few pages to each one and unmap them at disconnect.
- _wmd 11y agoPresumably most of the defences written for GCs are from people who haven't spent much time in C. Pool allocators are common elsewhere outside gaming, for example Samba's talloc, Apache httpd's APR and a bunch more places like e.g. boost::pool
- scott_s 11y agoThat actually has a name, and is explored in the literature: region-based memory management: https://en.wikipedia.org/wiki/Region-based_memory_management https://en.wikipedia.org/wiki/Region-based_memory_management