https://github.com/TTimo/doom3.gpl/blob/master/neo/idlib/Hea...
Surprisingly there's not a lot of platform-specific cruft in that code. The Xbox version of Doom3 must have been a separate code branch.
From the header comments:
/* ===============================================================================
Memory Management
This is a replacement for the compiler heap code (i.e. "C" malloc() and free() calls). On average 2.5-3.0 times faster than MSVC malloc()/free(). Worst case performance is 1.65 times faster and best case > 70 times.
=============================================================================== */
The Zone Memory Allocator(common.c: Z_Malloc, Z_Free,
Z_TagMalloc , Z_FreeTags) is still here in Quake2 but
it is pretty much useless:
Tagging is never used and allocation/deallocation is
build on top of malloc and free (I have no idea why id
software decided to trust the C Standard Library at this
point).
The overflow detector (using the Z_MAGIC contant) is
never used either.
So, unless I totally misunderstand things, it is half C stdlib, half Hunk allocator?That makes very little sense to do - every single project? Don't you think someone would have released a library to implement the "new and improved allocator" if everyone needs to use it?
There have been several successful efforts at writing better performing general-purpose allocators:
* TCMalloc (http://goog-perftools.sourceforge.net/doc/tcmalloc.html)
* jemalloc (http://www.canonware.com/jemalloc/)
There's a great Facebook Engineering blog post about jemalloc which describes why a fast allocator is needed & why the standard malloc is not always sufficient:
https://www.facebook.com/notes/facebook-engineering/scalable...Moderate usage of STL can do nasty, nasty things to memory performance. In one case a game I worked on ran at 5-10fps and a simple, fast change to DLMalloc instantly took perf to 60fps.
We used TCMalloc at Opera Community[0], and they still might be using it there for all I know ... it greatly improved performance on our MySQL servers!
[0]: http://my.opera.com/