I have a question about std :: vector <> performance in C ++. Is it easy to reuse the same vector by calling its clear () method, or does it recreate the vector faster?
In the following example, there is no real life code, this is only to clearly indicate that the question is:
//Example ONE: is this faster std::vector<int> foo; for(int i = 0; i < 100; ++i) { foo.clear(); for(int j = 0; j < 100; ++j) { foo.push_back(i+j); } } //Example TWO: or is that faster? for(int i = 0; i < 100; ++i) { std::vector<int> foo; for(int j = 0; j < 100; ++j) { foo.push_back(i+j); } }
source share