I'm making a small game engine and need to have a memory pool associated with it. My question is, how do I actually share that memory to users who got their own classes?
For example, I have a user who got this class in his game;
class Monkey : public GameObject {
public:
Monkey();
~Monkey();
void Eat();
void Sleep();
unsigned long size();
private:
int health;
};
I got a baseclass which, at the moment, just returns the size of the derived class. I figured this would be needed to know how much space this would occupy in the pool.
public GameObject {
public:
virtual unsigned long size()=0;
};
And he wants to allocate a new instance of this class in my memory pool. I do not know the class definition at compile time,so I just can't figure out how the actual method call would look like. He cannot pass me an object inheriting from GameObject, because that means he already has allocated it, which defeats the purpose of pre-allocated memory pool. So how does the reserving of memory actually work for any arbitary class instance?
Sorry if its unclear