C++ performance of accessing member variables versus local variables

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

    Using the member variables should be marginally faster since they only have to be allocated once (when the object is constructed) instead of every time the callback is invoked. But in comparison to the rest of the work you're probably doing I expect this would be a very tiny percentage. Benckmark both and see which is faster.

提交回复
热议问题