I have the following code which break up vectorOfInterest into smaller blocks to send out. this code is working.
However, I do a copy when I split the vectorOfInterest into smaller chunks (in the constructor of subList and remainder). is there a better to use move instead of duplicating the data again for better performance?
note that i cannot change the argument of OTHERCLASS::doSend()
Edit: i am using C++98
int blockSize = 50;
vector <CLASS_T> vectorOfInterest;
// ...<populates vectorOfInterest>
do {
if(vectorOfInterest.size()> blockSize)
vector<CLASS_T>iterator from = vectorOfInterest.begin();
vector<CLASS_T>iterator to = from + blockSize;
//elements are copied again in subList and remainder
//I like to move the elements from vectorOfInterest instead.
vector<CLASS_T> subList (from, to);
vector<CLASS_T> remainder (to, vectorOfInterest.end());
vectorOfInterest.swap(remainder);
OTHERCLASS::doSend (subList); // method which sends sublists in blocks of exactly 50 to external library
}else {
//pad to exactly size 50
vectorOfInterest.resize(blockSize);
OTHERCLASS::dosend (vectorOfInterest); // method which sends sublists in blocks of exactly 50 to external library
vectorOfInterest.clear();
}
while ( !vectorOfInterest.empty());