If you really want to append the data of b
and c
in vector a
, you have to do insertion (which actually is your 1.):
a.reserve( a.size() + b.size() + c.size() ); // preallocate memory (see why)
a.insert( a.end(), b.begin(), b.end() );
a.insert( a.end(), c.begin(), c.end() );
Depending on the compiler std::copy
(your 2.) should normally be as fast.
Since a std::vector
has always to be contiguous in memory, you can't just move (as defined in C++11) and if you know the end size you have to reserve your vector (it will avoid unnecessary reallocations of your vector). But if you really worry about performance, let this as three std::vector
and iterate over them when you have to read their data.