Original Post
Hey, how does a MemoryManager plugin sound?
My entire engine is based on a PluginSystem that only loads plugins and exposes them as services to other modules.
I have already made a LogManager, which I think sounded a good Idea in case you want to have remote logging etc...
Now I'm thinking of a MemoryManager as a Plugin as well
Something like this:
class Membase {
public:
//something like this:
void* operator new(size_t size)
the_memory_manager.new(size);
}
//and something like this:
void operator delete(void* p) {
the_memory_manager.delete(p);
}
static void setMemManager(IMemoryManager* mem_manager) {
the_memory_manager = mem_manager;
}
private:
static IMemoryManager* the_memory_manager;
};
Now when my engine is loading this will be one of the first modules that will load by default. And then I just set the manager with the setMemManager() and all classes that want to be managed need to derive from this class...
I would only use the memory manager during developement, so would the user of my library. Then during realease mode this would be disabled by a macro like:
//if active
#define MEM_MANAGED Membase
//else
class Empty_mem_class {
};
#define MEM_MANAGED Empty_mem_class
The memory manager could also be used to create objects instead of the ordinary new... but that would be terrible slow right?
Since not only doesn't the new/delete containe the code directly and not only does it redirect the call to the memory manager but it also does this with a virtual function call...
So how slow would this actually be?
thank you!
[edited by - bilsa on April 30, 2004 7:33:47 AM]