C ++ 64位int:按引用传递或按值传递 [英] C++ 64 bit int: pass by reference or pass by value
问题描述
这是关于64位整数的效率问题。假设我不需要修改 int参数的值,那么我应该通过值或引用传递它。
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.
假设使用32位计算机:
Assuming 32 bit machine:
1)32位整数:我猜测答案是按值传递,因为按引用传递会产生额外的内存查找开销。
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位int:如果我通过引用传递,我仅在堆栈上传递32位地址,但需要额外的内存查找。那么其中哪一个更好(参考或值)呢?
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)?
如果机器是64位呢?
问候
JP
推荐答案
按值传递-肯定是。如果系统是64位的,则意味着它非常快速地复制了64位字。
Pass by value - definitely. If the system is 64-bit it means it copies 64-bit word extremely fast.
这篇关于C ++ 64位int:按引用传递或按值传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!