Hacker News new | ask | show | jobs
by jcelerier 2087 days ago
imagine that my struct request looks like

   struct request { 
     int id;
     double parameter_value;
   };
surely moving does not gain anything - the original vector object still keeps the memory allocated, right ? sure, if you have complex requests with substrings, etc, but in that case I'd have `const auto&`-ed :)

(from my experience going full-throttle on movability when C++11 came out, I'd say that this was a mistake overall, much better to keep things as const& most of the time if you can. I've not yet reached a state where I consider the need for ownership transfer a code smell... but not very far :-))

1 comments

With the implementation your parent posted, the entire vector would be replaced with a fresh one. So the original vector would be deallocated entirely.

You could also do something with the drain method (which they posted originally and changed to the current implementation, not 100% sure why) and that would keep the memory around, yes, but then you'd be with only the high water mark of the number of requests, because it would be re-used.