Example Code
Download
Motivation
Overview
Completed Algorithms
In-Progress Algorithms
Source Code
Download
Memory Management
Eric's Memory Management API (EMMA) is a C++ memory management framework developed from the ground-up. The goal of this library is to "make memory management manageable" in C++, removing the mystery beyond handling memory in C++.
Motivation
I was doing some research one weekend, looking for a way to easily handle pooled objects in memory. I needed the ability to handle creation pool alignment seamlessly, with the option to track free and used memory in a variety of ways via different in-memory data structures (lists, trees, etc.). I quickly realized that the C++ standard libraries didn't provide much in terms of an extensible and lightweight memory management framework that could scale to meet the needs of any sized project.
So... like any good C++ developer, I took it as a challenge and decided to write my own.
When I started implementing EMMA, all I really wanted to do was to learn more about memory. As I began to accomplish this goal, I realized that I could keep going, turning what was a small handful of code into a professional memory framework. This gave me the ability to add cool new features, such as support for the popular TLSF algorithm and Doug Lea's dlmalloc allocator.
With the C++0x vote around the corner, I thought it would be fun to add some new features to the library. You'll see some use of auto, nullptr and static_cast throughout the code.
Overview
The key to effective C++ memory management (like many challenges in game development) is to reduce the problem's complexity into something manageable, if not simple. To do this I needed to abstract memory management into the following components:
- Allocators acquire and release memory
- Algorithms manipulate a subset of memory, responding to malloc and free requests
- Trackers track used and free memory
- Containers wrap algorithms to facilitate use and enable additional functionality (e.g. thread safety)
- Managers keep track of all containers/algorithms and any calls to acquire/release memory
Completed Algorithms
The library comes with the following algorithms already implemented.
- Two Level Segregate Fit (TLSF) A general-purpose algorithm that adapts well to applications with high flexibility requirements.
- Buddy A general-purpose algorithm that minimizes fragmentation by allocating memory in powers of 2.
- Fixed-sized Pools Pools with memory divided up into pre-determined allotments.
- Dynamically-sized Pools Pools that adapt to the runtime allocation requirements.
- Object-based Pools Pools that store objects and manage their creation and destruction events.
- Fixed-sized Stacks Stacks that prohibit individual free requests. Perfect for venue loading/unloading.
- Dynamically-sized Stacks Basic LIFO stacks with the ability to free large portions of memory at any time.
- Permanent Stacks Immutable stacks designed for permanent use. Perfect for allocations that must persist for the lifetime of the game.
- Circular Queues Array-based queues that provide for a pseudo-garbage collection capability.
- Fixed-sized Ranges A basic multi-pool algorithm.
- Delta Ranges A multi-pool algorithm based on Pascal's Triangle that favors smaller memory requests.
- Nabla Ranges A multi-pool algorithm based on Pascal's Triangle that favors larger memory requests.
In-Progress Algorithms
I'm currently adding the following memory algorithms to EMMA.
- Slab A general-purpose algorithm that minimizes external fragmentation and page cache misses by pre-allocating contiguous blocks of memory that service multiple requests for the same size.
- Arena A general-purpose algorithm that pre-allocates larger contiguous blocks of memory.
- Metamorph A custom-designed general-purpose algorithm that minimizes creation overhead.
Source Code
The following example project only contains a subset of EMMA. I'm holding off on releasing the entire library until I've had a chance to finalize the licensing. Please note that EMMA can only be used only for non-commercial purposes at this time.
You will need the following in order to build and test the example project.
- Visual Studio 2010
- I've included all the referenced Boost files in the download.
- EMMA is still a work-in-progress. As a result, I haven't tested a wide range of operating systems and compilers. Therefore, I can only attest to the code working properly under a 32bit version of Windows XP. Theoretically the library should work fine in other environments, including 64 bit and big-endian.
Download


