vector::reserve
why need to vector::reserve?
Do not the memory enough to use?
Need vector::reserve to avoid to short of memory?
The idea is that you can reserve a set number of elements that you know you will need so the vector does not have to reallocate memory when the vector gets larger.
So if you know your vector will need to hold at least 100 items, then you can reserve that amount to make the vector allocate enough memory for that number of items. If you do not use it, then the vector will reallocate memory as needed as items are added, which can possibly lead to slowdowns in your program.
So if you know your vector will need to hold at least 100 items, then you can reserve that amount to make the vector allocate enough memory for that number of items. If you do not use it, then the vector will reallocate memory as needed as items are added, which can possibly lead to slowdowns in your program.
Quote:Original post by Drew_Benton
The idea is that you can reserve a set number of elements that you know you will need so the vector does not have to reallocate memory when the vector gets larger.
So if you know your vector will need to hold at least 100 items, then you can reserve that amount to make the vector allocate enough memory for that number of items. If you do not use it, then the vector will reallocate memory as needed as items are added, which can possibly lead to slowdowns in your program.
clear. thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement