I'm working on a project that will load 3D models from an archive into memory for use by an OpenGL rendering engine. I am creating a C++ class (the entire project is C++ and will be cross-platform) for loading, manipulating, and freeing the objects. The thing is, I can allocate the class in an array and loop through the array or I could create it as a linked-list. My question is which method is better? Speed is a priority since there may be several thousand loaded at any point in time, and I can't wait for ages for it to locate a single object. Examples of my current usage ideas are below.
pObject = (ObjectData)malloc(sizeof(ObjectData));
//Assume we loaded a bunch of objects in
for(int iLoop = 0; iLoop < ObjectCount; iLoop++)
if(pObject[iLoop].ID == WhateverID)
pObject = new class ObjectData;
//Assume we loaded a bunch in, again
In the second example, the "Find(int)" method would compare the specified ID to its own ID. If the ID matches, it returns itself, but if not and the pointer to the next "ObjectData" is not NULL, it calls the next object find method, and this continues until the object is found or until the next object pointer is NULL, and it returns NULL.