parameters for function : const reference and constant data pointer

Asked

Viewed 320 times

2

what is the difference in performance ( in the case of large object) the calls below:

void funcao( const tipo  &objeto )

and

void funcao( const tipo *objeto )

I know that the first receives a constant reference, which is good not to need to copy the object , only creates a nickname for the object, and how and const, the object cannot be modified;

and (I know that) in the second receives the address of the object , and how is const, the object cannot be modified.

  • 1

    Good question. I believe that if there is a performance difference it will be very small, because probably the compiler turns in this differentiation. P.S.: It’s going to be one of those questions that only @bigown solves. :)

1 answer

1


In principle it makes no difference, since the obvious implementation of a parameter by reference is simply a pointer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.