C++ and QT4.5 - is passing a const int& overkill? Does pass by reference helps in signals/slots?

前端 未结 3 895
-上瘾入骨i
-上瘾入骨i 2021-02-15 16:02

Two questions rolled into one here...

I have a number of functions which are called multiple times per frame for a real-time video processing application. Taking advice

3条回答
  •  天涯浪人
    2021-02-15 16:24

    Yes, pass by reference helps against copying the objects. But the compiler might decide to optimize it out entirely and insted pass by value if it produces the same effect. Such optimization is usually possible if the function and the call site are in the same translation unit but some compilers can do even more global optimizations - you can inspect the emitted assembly if you care.

    This is why you really shouldn't pass primitive types by reference if you care about performance and unless you really have reasons for that. See What is the use of passing const references to primitive types? for discussion of that problem.

提交回复
热议问题