Suppose I am using a vector of int a:
vector<int> a {1, 2, 34, 1222, 0};
Then, I want to push_back some datas like this:
a.push_back (data);
However, my program have to add a lot of data on my vector.
I am learning c++ on a book. The book says: "Adding an element can sometimes require additional storage be allocated. In that case, every element must be moved into the new storage", the c++ Ressources Network adding that "This is a relatively expensive task in terms of processing time.". I also find an article about the subject.
However, my program have to be very fast. So, I can not deal with this "relocation" of my vector. In fact the size of my vector can be up than 1GO of memory.
My question is quite simple:
How can I know the remaining memory before relocating my huge vector?
Note: I do not know the finally size of my vector so I can not initialize it keeping the necessary memory.
Tell me if you have some questions or some comments.