Answer the question
In order to leave comments, you need to log in
Does it make sense to pass STL container by reference to function parameters to save memory and increase speed?
Or do modern compilers (primarily gcc) optimize this moment themselves?
The question arose after reading this article www.habrahabr.ru/post/117193, paragraph: Transferring everything and everywhere by pointers (links)
Answer the question
In order to leave comments, you need to log in
Certainly has. How should the compiler know, maybe you really want to work with a copy, and not with the original.
Another matter, return from function. RVO (return value optimization) works there, so you can not worry, but simply give the container.
Or do modern compilers (primarily gcc) optimize this moment themselves?
It doesn't "make sense", but the first rule. But the compiler is forbidden to optimize this, the semantics of the code changes from this, and not only optimization is done.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question