Cost of passing by reference when a template type is fundamental

给你一囗甜甜゛ 提交于 2019-12-04 09:47:34

If the compiler is really inlining the code (which is common for simple templates) there will be no difference. The problem becomes apparent when the function cannot be inlined, and the out-of-line definition is called.

In that case, passing a reference can involve an extra dereference when accessing the variable (at the very least the first time, possibly multiple times) At the same time, the compiler can perform more aggressive optimizations if the argument is by value, since it knows that the variable cannot be accessed/modified outside of the current function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!