C++ Performance – Pass 64 Bit Int by Reference or Value

32bit-64bitc++pass-by-referenceperformancex86-64

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

Best Answer

Pass by value - definitely. If the system is 64-bit it means it copies 64-bit word extremely fast.