Currently, the client programmer can create memory pools of varying sizes (these sizes are all rounded up to the nearest kilobyte).
Here's an example of the pools working (and they actually work, a rarity for my code).
#include #include #include "Pool.h"using namespace std;using namespace stratus;using namespace memory;int main(int argc, char** argv){ try { //TEST: Make sure all implemented pool functions work //////////////////////////////////////////////////////////////////////////// //we want only 20 ints, but we get a Kilobyte worth Pool<int> testPool("Test Integers.", 20); //create one integer int* testInt = testPool.Allocate(); int* testInt2 = testPool.Allocate(); int* testInt3 = testPool.Allocate(); *testInt = 10; *testInt2 = 20; *testInt3 = 3005; cout << "Value of int 1: " << *testInt << endl << "Value of int 2: " << *testInt2 << endl << "Value of int 3: " << *testInt3 << endl; cout << endl << "---------------------------------" << endl << endl; cout << "Total size in bytes: " << testPool.GetTotalSize() << endl; cout << "Total free blocks: " << testPool.NumberOfFreeBlocks() << endl; cout << "Total free bytes: " << testPool.NumberOfFreeBytes() << endl; cout << "Largest Free Strip in Blocks: " << testPool.GetLargestUnfragmentedBlockSize() << endl; cout << "Largest Free Strip in Bytes: " << testPool.GetLargestUnfragmentedByteSize() << endl; //////////////////////////////////////////////////////////////////////////// //RESULT:SUCCESS system("PAUSE"); return 0; } catch(const MemoryException& error) { cout << error.what() << endl; system("PAUSE"); exit(1); }}
this outputs:
Note that you have to name the memory pools. This is useful because whenever there is a memory error, it will throw the error as well as the pool that it happened in. Also, I plan on making a
"Memory Manager" class that will contain pools, and perform the garbage collection incrementally.
Also note that fragmentation is not an issue at all. The Allocate() function determines whether it is acceptable to allocate the memory at the end of the current strip or look from the beginning for a free block.
I don't like having to use Allocate so much, so I will make it to where other parts of my game engine allow you to just enter the name of the pool to use in their constructor.
I'm looking at your Windows color settings in your screen shots and they are the EXACT colors I use! These were colors I customized. Coincidence?
3D objects: 131, 153, 177
Active Title bar: 79, 101, 125 fades to 128, 180, 208