Jump to content
  • Advertisement
Sign in to follow this  
Richy2k

STL, memory allocation, and speed.

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

I've just spent all night getting rid of as much of my shoddy code in my engine, and decided I may aswell use STL, i'm new to making game engines, so whats the harm? Anyways, I know vaguely how the std::vector works, but i'm curious on one thing - is it possible to force it to allocate a large chunk of memory for itself so it doesn't need to keep reallocating everytime an object is removed or it is cleared? I am wondering as I store pointers to all meshes to be rendered in a vector, then render them all out at once, but this requires the list to be cleared at the end of each run.

Share this post


Link to post
Share on other sites
Advertisement
A vector does not automatically shrink its reserved space when elements are removed. Much like Richard Marx, it holds on to the memory.

Share this post


Link to post
Share on other sites
Ah thank god for that, is there a way I could allocate all the memory before hand? Or would I just need to shove a load of elements into the vector and then clear it?

Share this post


Link to post
Share on other sites
If you really think allocation is the bottleneck you can use different tricks.

Use 'static' vector () , list with garbage collector (list::splice) and in general a custom allocator (implemented by your mem manager)

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!