Jump to content
  • Advertisement
Sign in to follow this  
leoptimus

std::vector Performance

This topic is 4833 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

For hight performance games, Using Standard C++ Library types is forbiden? I mean if using std:vector would slow down the machine performance. Suppose that, on a 3D game, it's necessary to manage a big collection of vertices and doing many mathematical operations, geometry querys and so on... It's better using conventional C pointer arrays than std::vector instead? And, If it's provided a allocator to std:vector objects for managing memory, it would increase performance?

Share this post


Link to post
Share on other sites
Advertisement
Assuming a decent optimizing compiler, and assuming you don't do anything particularly stupid, using std::vector in place of manually managed dynamic arrays should show no performance difference.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make sure you use reserve() to pre-allocate some reasonable amount of memory, so you don't get hit with a suprise reallocation on a push_back()

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Assuming a decent optimizing compiler, and assuming you don't do anything particularly stupid, using std::vector in place of manually managed dynamic arrays should show no performance difference.


Correction, std::vector may in fact end up faster due to the fact that it doubles the memory allocated each time rather than reallocating in a linear manner.

Quote:
It's better using conventional C pointer arrays than std::vector instead?


By itself definately no. With a lot of custom tracking it'd be possible, but you might as well invest in building yourself a custom allocator instead of wasting time reimplementing bits of std::vector, which is more or less what you'd be donig.

Quote:
And, If it's provided a allocator to std:vector objects for managing memory, it would increase performance?


Depends - it comes with a standard default one of course. The Boost Pool Library includes a couple allocators which may speed preformance. You may be able to write a custom one that will preform better in certain specific situations, but for a general all around good allocator, the default one will be hard to beat.

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!