C++ function parameters: use a reference or a pointer (and then dereference)?

后端 未结 11 2210
臣服心动
臣服心动 2021-02-05 10:49

I was given some code in which some of the parameters are pointers, and then the pointers are dereferenced to provide values. I was concerned that the pointer dereferencing wou

11条回答
  •  后悔当初
    2021-02-05 11:23

    From a performance point of view, it probably doesn't matter. Others have already answered that.

    Having said that, I have yet not found a situation where an added instruction in this case would make a noticeable difference. I do realize that for a function that is called billions of times, it could make a difference. As a rule, you shouldn't adapt your programming style for these kind of "optimizations".

提交回复
热议问题