不同的component根据id,放在数组中
class Person
{
};
struct Pool_Data
{
int _component_id{ 0 };
Person* _pool{ nullptr };
Pool_Data()
{
cout << "Pool_Data" << endl;
}
};
vector<Pool_Data> _pools;
auto* assure(int type)
{
Pool_Data* p = nullptr;
if (type >= _pools.size())
{
_pools.reserve(type << 1);
while (type >= _pools.size())
{
_pools.emplace_back();
}
}
p = &_pools[type];
if (nullptr == p->_pool)
{
p->_component_id = type;
p->_pool = new Person;
}
return static_cast<Person*>(p->_pool);
}
int main()
{
auto a1 = assure(1);
auto a2 = assure(1);
auto a3 = assure(3);
return 0;
}