C++ performance of accessing member variables versus local variables

后端 未结 11 2081
别那么骄傲
别那么骄傲 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:49

    It depends, but I expect there would be absolutely no difference.

    What is important is this: Using member variables as temporaries will make your code non-reentrant - For example, it will fail if two threads try to call callback() on the same object. Using static locals (or static member variables) is even worse, because then your code will fail if two threads try to call callback() on any thisClass object - or descendant.

提交回复
热议问题