ABSTRACT

Alternatives to Rolling Your Own  Surely someone has already written a good heap. Doug Lea’s dlmalloc is one of the best and is typically the memory manager of choice on Linux. There are many derivatives on the internet that claim some improvements, but there are many flavors to choose from. dlmalloc is a good choice primarily because it’s very stable and well-tested, it’s public domain code that is freely available, and it runs on 32-bit and 64-bit systems of either endianness. Very compelling. The main gripes with dlmalloc is that it is a mess to look at, it’s horrible to debug in case of heap corruption, and it’s easily corrupted in case of a buffer overrun. As for usability, there’s no way to create one-off heaps with it that have been optimized for special use cases, where you can predict sizes and counts of allocations. dlmalloc also has a fairly high per-allocation overhead that chews up memory. As general-purpose heaps go, it’s excellent, but for games, we sometimes need custom solutions with more bells and whistles.