I
Ivan Vecerina
"Lasse Skyum" <lskyum(AT)mail.dk> wrote in message
| For my renderer at each frame I'm filling a vector with CVisual* elements,
| sorting it, rendering the objects and then clearing the vector again.
|
| I suspect there will be an overhead if the vector is resizing it's
capacity
| all the time... is there a way to prevent this?
An std::vector instance will NOT release the memory it has allocated
when its size is reduced, or when it is emptied ( by calling its
clear() member ). So resizing a vector of pointers can only trigger
a memory reallocation if its new size is larger than what it has
ever been - the capacity is preserved by default.
For the elements that are added/removed by calling resize(), there
can still be, however, a small overhead for initializing/destroying
elements (but for pointers, the destructions will be optimized out
on a good library implementation).
Regards,
Ivan
| For my renderer at each frame I'm filling a vector with CVisual* elements,
| sorting it, rendering the objects and then clearing the vector again.
|
| I suspect there will be an overhead if the vector is resizing it's
capacity
| all the time... is there a way to prevent this?
An std::vector instance will NOT release the memory it has allocated
when its size is reduced, or when it is emptied ( by calling its
clear() member ). So resizing a vector of pointers can only trigger
a memory reallocation if its new size is larger than what it has
ever been - the capacity is preserved by default.
For the elements that are added/removed by calling resize(), there
can still be, however, a small overhead for initializing/destroying
elements (but for pointers, the destructions will be optimized out
on a good library implementation).
Regards,
Ivan