C++ performance of accessing member variables versus local variables

后端 未结 11 2017
别那么骄傲
别那么骄傲 2020-12-04 22:07

Is it more efficient for a class to access member variables or local variables? For example, suppose you have a (callback) method whose sole responsibility is to receive dat

11条回答
  •  离开以前
    2020-12-04 22:38

    I'd prefer the local variables on general principles, because they minimize evil mutable state in your program. As for performance, your profiler will tell you all you need to know. Locals should be faster for ints and perhaps other builtins, because they can be put in registers.

提交回复
热议问题