Let's assume the vector memVec is a private member of class A, i.e. an lvalue. What would be a good way to pass it to class B for further processing?
Note that memVec does not need to retain its data beyond the exchange.
Could I create an empty vector inside A's return function and swap it in-place to return a movable rvalue?
Note that memVec will be filled with a virtually identical amount of data (give or take 1KB) many times over. So I intend to callCode:std::vector<char> A::next() { std::vector<char> tempVec; memVec.swap(tempVec); return tempVec; }
on it after every exchange/swap, which I imagine would still be better than copying the vector to B and calling memVec.clear(). What are your thoughts?Code:memVec.reserve(moreThanEnoughRoom);