Platforms: Windows x86, x64, Unix, Linux, OSX, iOS
VMem - Fast and efficient
C++ malloc replacement
Product | Platform | Developer |
L.A. Noire | PS4 / XBox One / Switch / Windows | Rockstar Games |
Final Fantasy XV | PS4 / XBox One / Windows | Square Enix |
Don't Starve Together | PS4 | Klei Entertainment |
Deus Ex: Mankind Divided | PS4 / XBox One | Eidos Montreal |
Fable Legends | Windows / XBox One | Lionhead Studios |
Rise of the Tomb Raider | XBox360 | Crystal Dynamics |
XCOM Enemy Unknown | Windows, XBox360, iOS | 2K Games |
VMem is a C++ memory manager. It is used as a general purpose malloc replacement. VMem has minimal overhead in terms of both memory and CPU, and is specifically designed for multi-threaded environments. VMem uses advanced techniques to reduce fragmentation, making it the perfect choice for platforms with fixed memory, such as games consoles.
There are already many free and commercial memory managers available, so what makes VMem unique? Unlike VMem, most allocations are not specifically designed for a multi-threaded environment. Often, all they do is take a single lock around the global allocation and free. VMem's multi-tiered locking makes it the perfect choice for modern games.
All allocators do their best to combat memory fragmentation, but on consoles which have a fixed memory budget this is not always enough. It is typical for modern game engines to make tens of thousands of allocations per second, and most games have to run for many hours, whilst making many level transitions without running out of memory. Fragmentation can be a huge concern. This is where VMem excels - it is specifically designed to limit fragmentation in a fixed memory environment.
VMem has extensive error checking and will detect problems that many other allocators miss. Whether it's a double free, buffer overrun or writing to a deleted object, VMem will detect problems before they go on to do further damage. This can save weeks of valuable time spent tracking down the most difficult and elusive of bugs.
The VMem code is clean and well documented C++ code. Ideally, you shouldn't ever have to know how your allocator works internally, but the reality is that memory corruption bugs are not uncommon in the games industry. When you do have memory bugs you often need to dive in to the memory manager code, and the VMem code is clear and easy to understand.
There is a technical paper describing exactly how VMem is structured and how each feature works. Below is a summary of the main points.
Like most memory managers, VMem consists of a number heaps. It has two small object heaps, two medium-sized coalesce heaps and a large heap. The two small heaps are backed by a shared page heap. VMem makes optimal use of virtual memory. While most allocators commit large regions of memory from the system before carving them up, VMem only reserves the memory and commits and decommits pages as necessary. Any system page that is not currently in use by your application is always freed back to the system. Each heap dynamically resizes itself to the smallest size possible. This makes VMem a self-balancing system, which will always use the minimum amount of memory possible.
VMem is licensed under a dual license: a free license for open-source projects, and a commercial license to allow it to be used in commercial projects. Read more about the licensing here.
VMem is a thread-safe, low fragmentation
malloc replacement
VMem's multi-tiered locking makes VMem a perfect choice for modern games
VMem is specifically designed to limit fragmentation in a fixed memory environment
VMem has extensive error checking and often catches problems that many other allocators miss