I'm running Windows 7 with a Core Duo. I've been using Codeblocks for a while now, which I think I have using GNU compiler.
I have (or will have) many component classes that inherit from the abstract class Component
. I need help establishing a system to house memory pools for an undetermined amount of component types, each with an undetermined amount of components. Maybe for the sake of argument the latter is fixed, I can figure out how to change size when abolutely necessary.
Also, conveniently so, each component type has an ID (unsigned short
) from 0 to whatever with no holes. Yay!
So, assuming I have some managing clas to keep track of array sizes and things, would something like this work?
class开发者_如何学Go Component {};
class FooComponent: public Component {};
class BarComponent: public Component {};
.
.
.
std::vector<Component*> pool_list;
// returns pointer to beginning of pool
Component* foo_pool = MethodToCreateComponentPool(/* Params */)
Component* bar_pool = MethodToCreateComponentPool(/* Params */)
pool_list.push_back(foo_pool);
pool_list.push_back(bar_pool);
Maybe put sizeof(FooComponent)
in for Params.
Then (Where I really start to not know what to do) inside the function do an malloc( START_COUNT * component_size)
I have no experience allocating memory like this. I can easily set up something like
vector< vector<Component*>* >
or
map<unsigned short, vector<Component*> >
but it (is ugly for one) doesn't give me contiguous pools. I need cache friendly :)
Ideas? Patterns? Idioms? Help?
I got wrapped up in how I was implementing this and lost track of what I really needed. Which is basically this post.
Thanks.
精彩评论