Hi friends,
Let me introduce my self first, i am krishna alijala, new user to this forum. i need some clarification on vectors and arrays.
as of my knowledge:
Vectors: when we create vector of some objects compiler will reserve large amount memory for this vector. so that when we push object it will store that object. as soon as program reaches to maximu size of vector it will again uses reallocate memory.
Dynamic Array: Assume that we have reserved large amount memory. after filling the reserved space here also we will use "reallocate".
please answer for following questions
1)Vectors: if compiler reserve large memory for small amount data, is this not wasting memory unwantedly?
2) What is difference between Vector and Dynamic allocation of an Array
3) please let me know any performence issue also.
1)Vectors: if compiler reserve large memory for small amount data, is this not wasting memory unwantedly?
If you have to reallocate and copy around memory every time you add one more object to your container, you waste lots of processor cycles. It's a trade-off you make; runs faster, uses memory it might not have needed.
If you have an idea of how much memory you will need, you can instruct how much memory to reserve for the vector.