   STL linked list, vector and arrays
  Hi people!I've been working on a object generator for my plugin system and I have a doubt in how to store my object data. A simple drawing method is something like this:for(i = 0 ; i < triangles ; i++){tris = triangles.get(i);v[0] = vertex.get(tris[0]);v[1] = vertex.get(tris[1]);v[2] = vertex.get(tris[2]);glBegin(GL_TRIANGLES);glVertex3f(v[0].x,v[0].y,v[0].z);glVertex3f(v[1].x,v[1].y,v[1].z);glVertex3f(v[2].x,v[2].y,v[2].z);glEnd();}In a object generator is essential to have index(triangles) and vertex modifiying control, so I need something like a linked list but with the array reading efficiency. I've been testing the STL vector class and i'm not sure if the results are the necessary ones. <vector> testing results:I: insertingR: retrievingD: deletingI: 100: 0 msR: 100: 0 msD: 100: 0 ms I: 1000: 0 msR: 1000: 0 msD: 1000: 1 msI: 10000: 5 msR: 10000: 5 msD: 10000: 15 msI: 100000: 52 msR: 100000: 48 msD: 100000: 146 msI: 1000000: 501 msR: 1000000: 470 msD: 1000000: 1509 msI: 10000000: 5148 msR: 10000000: 4679 msD: 10000000: 14782 msMy idea is to combine the STL vector and arrays, when I need performance, call some optimize function to convert <vector> data into array and retrieve all information from that array.I'm not sure if I've explained my problem clear...Some suggestion, idea, flame, blabla?Thanks in advance :)PD.: the deleting method if someone is interested:for(k = 0 ; k < init ; k++){std::swap(v[init-k-1], v.back());v.pop_back();}   
  Hi bud,Altering an STL vectors contents via its interface is going to be no slower that altering a typical array.I think the question you should be asking yourself here is whether you really need to be doing this or not.For what reason do you want to do this?Dave   ;  What he said. Make sure you are profiling release builds with optimizations and all, and the vector should be pretty much on par with a raw array. I would give your "triangle" data structure a draw() method or something to handle the drawing through a rendering abstraction layer than the caller getting each vert and calling raw immediate mode rendering methods of opengl.   ;Quote:Original post by pfc6so I need something like a linked list but with the array reading efficiency.That would (roughly) be std::deque but there are other alternatives too.Quote:Original post by pfc6My idea is to combine the STL vector and arrays, when I need performance, call some optimize function to convert <vector> data into array and retrieve all information from that array.Pointless, std::vector is a dynamic array, std::vector is not implementated with a linked list.You could do much better with your drawing code and you're probably using std::vector ineffectively or using the wrong data structure for the job, but it's hard to say without seeing what you're actually doing.[Edited by - snk_kid on June 1, 2006 5:02:59 AM];  When I need to modify for example an object face doing an extrude, I need to add more faces and modify my indexes 'vector'. Accesing to the STL vector element is exactly the same as accessing to an array element?. I have a trouble with this... accessing to an 'real' array is faster I think...I am mistaken?Thanks again.   ;  The only instance when a 'real' array would be faster than std::vector would be if it was statically sized i.e. on the stack or in global memory and of a fixed size. If the 'real' array is dynamic i.e. on the heap and resizable, it will not be significantly faster than std::vector if at all.   ;Quote:Original post by pfc6I am mistaken?The short answer is: Yes.   ;  Thanks for all the replys.   