STL, memory allocation, and speed.
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.
A vector does not automatically shrink its reserved space when elements are removed. Much like Richard Marx, it holds on to the memory.
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?
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)
Use 'static' vector () , list with garbage collector (list::splice) and in general a custom allocator (implemented by your mem manager)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement