I'm merging many objects into a single vector containing render data (a mesh). This vector gets cleared and refilled on each frame (well, almost).
The issue is that clearing and then again reserving the vector size has a huge impact on performance in my case, because clear()
may also change the capacity.
In other words, I need to control when the capacity of the vector gets changed. I want to keep the old capacity for quite some time, until I decide myself that it's time to change it.
I see two options:
- Figure out how to control when the capacity of
std::vector
is about to change - Implement a memory pool for large memory objects which will fetch a large data object of <= required size and reuse / release it as I need.
Update
In addition, what if for example a resize(10)
, and later a resize(5)
was called (just for illustration, multiply actual numbers by some millions)?
Will the later call to resize(5)
cause the vector to, maybe, reallocate?