Jump to content
  • Advertisement
Sign in to follow this  
pfc6

STL linked list, vector and arrays

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: inserting R: retrieving D: deleting I: 100: 0 ms R: 100: 0 ms D: 100: 0 ms I: 1000: 0 ms R: 1000: 0 ms D: 1000: 1 ms I: 10000: 5 ms R: 10000: 5 ms D: 10000: 15 ms I: 100000: 52 ms R: 100000: 48 ms D: 100000: 146 ms I: 1000000: 501 ms R: 1000000: 470 ms D: 1000000: 1509 ms I: 10000000: 5148 ms R: 10000000: 4679 ms D: 10000000: 14782 ms My 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(); }

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by pfc6
so 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 pfc6
My 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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!