Hi guys,
I want to ask you what are the best practices to dynamically create and manage objects in a real time environment. Basically, I need to create a bunch of objects on the fly. If the objects meet the criteria, they will be played and then destroyed after a while. So far I’m trying with an OwnedArray, but it doesn’t seem to retain the objects at the required index.
What I currently do is, basically, this:
for(int i = 0; i < maxItems; ++i)
{
if(shouldBePlayed[i] == true)
{
if(myObj* obj = objArray[i])
{
output += obj->play();
if(obj->ended())
{
objArray.remove(i);
shouldBePlayed[i] = false;
}
}
}
if(shouleBePlayed[i] == false)
{
myObj* obj = new myObj();
objArray.set(i, obj);
obj->init();
shouldBePlayed[i] = true;
}
}
The main issue is that the objects are created but almost never destroyed because I get a nullptr at objArray[i]. That’s why I think OwnedArray might not be the perfect way to handle that.
Any advice?
Thanks!