Which is faster?
I am currently implementing a manager class containing 300+ objects of the same class with a draw method.
Would it be faster to contain all 300+ objects in an std::vector<> and iterate through each one. Or should I create a linked list that returns a pointer to the next object?
Speed is of the essence so everything down to compiler optimisation is a bonus.
Example of first method:
std::vector<Object*>::iterator ObjectIterator;
for(ObjectIterator = ObjectVector.begin(); ObjectIterator != ObjectVector.end(); ++ObjectIterator)
{
ObjectIterator->draw();
}
Example of second method
Object* Object::draw()
{
// Code to do drawing of VBO/Vertex List
return _nextObject;
}
// Assume ObjectManager holds a pointer to the First object of the LL
void ObjectManager::Draw()
{
currentObject = firstObject->draw();
while(currentObject)
{
currentObject = currentObject->draw();
}
}
Thanks for any advice
EDIT: Just realised I didn't fully explain.
Obviously with the second method, you would presume ObjectManager wouldn't contain any information regarding other Objects than the first. However I will need access to them. Therefor, I'm already storing a vector of the Objects. So memory management is not a deciding factor.
[Edited by - Sneftel on November 25, 2008 8:41:43 AM]