C++ 64 位 int:按引用传递或按值传递 [英] C++ 64 bit int: pass by reference or pass by value

查看:40
本文介绍了C++ 64 位 int:按引用传递或按值传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个关于 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 位整数:如果我通过引用传递,我只在堆栈上传递 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 位呢?

What if the machine is 64 bit?

问候,

日本

推荐答案

传值 - 肯定的.如果系统是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆