Merge arrays or vectors

I'm about to make a part of a program where I merge data stored in different vectors, or arrays depending on how smooth merging the two structures are.

Whats the fastest way of doing it? Allocate a big array, or vector and iterate in content from the parts I'm merging. Or is there some core function that does it better..?

Any advice would be appreciated. :-)
1
2
3
4
5
6
vector<MyStruct> a;
vectot<MyStruct> b;
//fill a and b with stuff
vector<MyStruct> t (a);
t.reserve(a.size()+b.size());
t.insert(t.end(), b.begin(), b.end());
Maybe?
http://www.cplusplus.com/reference/stl/vector/reserve/
http://www.cplusplus.com/reference/stl/vector/insert/
Last edited on
Topic archived. No new replies allowed.