Jump to content
  • Advertisement
Sign in to follow this  
juglar

boost::ptr_vector performace problems :

This topic is 3883 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 folks ,i'm doing some tests, with boost::ptr_vector, i have a class who load objets in a simple format, i load this format in a simple raw pointer like this Vertex p = new Vertex[countPoints]; and in the render step i take the information using the [] like this p[face.a] but when i change it to boost::ptr_vector a lost a LOT of performance , with row pointer i get 466 FPS, with boost::ptr_vector 210 FPS, i know i will have a performance cost for use boost::ptr_vector, but this is a LOT of lost in performance ... it is true or i have a bad concept to try to save the vertex in a boost::ptr_vector for remplace the raw pointer to a boost::ptr_vector i save each vertex with boost::ptr_vector::push_back an get the vertex with the [] operator if you have any tip to help me in that performace problem i will apreciete thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
From what you posted, it looks like you probably want std::vector, not boost::ptr_vector.

Can you post some of your code so that we can see how exactly you're using boost::ptr_vector?

Share this post


Link to post
Share on other sites
Well, first of all, don't measure performance in FPS. It's a stupid metric. Your scary sounding 466 FPS to 210 FPS drop, for instance, is really just about two and a half milliseconds per frame. The reciprocal nature of FPS makes it lousy for comparisons like these.

I really can't see, though, why anybody would ever want to use a ptr_vector for storing mesh vertices. The only way you should ever store vertices is in a packed array (or equivalent contiguous container, like std::vector) which can be directly given to the card as a vertex array or VBO. What functionality are you trying to gain with ptr_vector?

Share this post


Link to post
Share on other sites
thanks to all for your fast reply! i just want to use ptr_vector to store pointer to Vertex .... but reading your post mybe i'm wrong and the std::vector is the correct way to to do that :)

Share this post


Link to post
Share on other sites
Quote:

but reading your post mybe i'm wrong and the std::vector is the correct way to to do that :)

Yes, std::vector is the correct way. Unless you're using immediate mode in OpenGL, where you can individually submit each vertex, you neeed your vertices in a contiguous block of storage to submit them to the card. std::vector provides that. As a result, it is also more efficient when traversing linearly across the entire vector, as I suspect you are doing (in conjunction with GL's immediate-mode functions). The reason is because it is more cache-friendly to have all the vertex data nearby; memory is all fetched from generally the same location, which is likely already cached from a previous fetch to that area, and thus you make less cache misses.

Each element in a ptr_vector is a pointer. While the pointers will be contiguous in memory, the data they point to -- the vertices, would most likely not be. In fact they may be scattered all over the heap. Traversing a ptr_vector linearly like this is likely to induce more cache misses; on a large enough data set, this will degrade performance to some extent.

Share this post


Link to post
Share on other sites
Quote:
Original post by juglar
jpetrie, thanks for the info, i'm using OpenGL if i use imediate mode what do you recomend?
std::vector is probably still the best option (plus, you'll probably want to switch to vertex arrays at some point anyway for performance reasons).

Share this post


Link to post
Share on other sites
Quote:
Original post by juglar
jpetrie, thanks for the info, i'm using OpenGL if i use imediate mode what do you recomend?

Not using immediate mode.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
The only way you should ever store vertices is in a packed array (or equivalent contiguous container, like std::vector) which can be directly given to the card as a vertex array or VBO. What functionality are you trying to gain with ptr_vector?


If you are loading from a file format like obj that stores "vertex data" like position, normal, and textureCoords separately then it is necessary to store them in an intermediate format as independent vector/arrays...in addition it seems easier to do calculations such as dynamic changes to the mesh or calculation of vertex tangents.

If you use D3DPOOL_MANAGED then there is no need to maintain a contiguous container in GPU form because you'll never need to pass them manually to the graphics card more than once, so there would be no point to maintaining an array in that form anyway.

Storing the data in a custom structure like "Vector3" makes it a lot easier to do arithmetic, which would be the only purpose of saving that data that I can think of. But if you don't use a vector of pointers, then you have to invoke a lot of extra constructors/assignment-ops, which is a lot less efficient...and you also cannot conveniently use the constructor when adding new objects like you can with pointers. So, it seems to me that a vector of pointers is the way to go.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!