Alex Rivera | Logout

C++ 64 bit int: pass by reference or pass by value

Asked 2010-11-10T10:50:20.580
18

This is an efficiency question about 64 bit ints. Assuming I don't need to modify the value of a "int" parameter, should I pass it by value or reference.

Assuming 32 bit machine:

1) 32 bit int: I guess the answer is "pass by value" as "pass by reference" will have overhead of extra memory lookup.

2) 64 bit int: If I pass by reference, I only pass 32 bit address on the stack, but need an extra memory lookup. So which one of them is better (reference or value)?

What if the machine is 64 bit?

regards,

JP

Edit
Report

1 Answer

12

Even on a 64 bit machine pass by value is better (with some very few exceptions), because it can be passed as a register value.

answered 2010-11-10T10:54:26.297

Your Answer