I have a function that reads lines from a log file, converts these lines to a certain class and returns a STL list of instances of this class.
My question is: how should I declare this function so that the whole list is NOT copied when attributing it to the caller? Without loss of generality, assume:
list<Request> requests = log_manipulator.getAsRequestList();
How should I declare getAsRequestList()? Returning a reference to a list or just returning a list?
This is a serious issue because in this particular assignment the lists will contain circa 1.5M elements, and thus a mistake like that can screw up memory usage.
Thanks in advance.