c++11 - inserting into vectors c++ -


i need push 66,000 vectors (the number of vectors not fixed, can 90,000 vectors also. sake of brevity showing below code example of 66,000 vectors) of type vector following vector:

vector<int> vec; 

the size of each of 66,000 vectors 9,000 elements. using following doing same:

vec.reserve(66000*9000); for(int j=0;j<66000;j++)     for(int i=0;i<9000;i++) //9000 elements in vec1[i] per vector not fixed         vec.push_back(vec1[i]); //i pushing example 

is there someway may increase efficiency of code?

i need concatenate many vectors, solution same potentially different concatenating 2 vectors. can not use multi-threading mentioned in previous question

try following

std::vector<int> vec; vec.reserve( 66000*other_vec.size() );  ( size_t = 0; < 66000; i++ )  {     vec.insert( vec.end(), other_vec.begin(), other_vec.end() ); } 

Comments