... my problem was only that in vectors, even if i knew the exact number of vertices, the vector would allocate extra memory for future pushes or pops
[/quote]
It only does this if you start pushing. If you use resize(), you can essentially control how often and how much memory is allocated.
The main benefit of using std::vector over raw pointers is that it will not leak. It won't leak if you return early from a function, it won't leak if an exception is thrown. Other advantages include checks during Debug builds that you aren't stepping outside the bounds of the vector.
If for whatever reason you're not going to use std::vector, I totally recommend that you at least write a small class to encapsulate the memory management. You can get both of the above advantages if you wrap the raw pointer in a small class.
[C++] Dynamic Memory Deallocation
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement