在...循环中使用short而不是int的好处 [英] Benefit of using short instead of int in for... loop

查看:426
本文介绍了在...循环中使用short而不是int的好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在for循环中使用short而不是int有什么好处吗?
ie

is there any benefit to using short instead of int in a for loop? i.e.

for(short j = 0; j < 5; j++) {

99%的循环涉及到3000以下的数字,所以我认为int会浪费字节。谢谢!

99% of my loops involve numbers below 3000, so I was thinking ints would be a waste of bytes. Thanks!

推荐答案

不,没有好处。短路可能会结束采取一个完整的寄存器(这是32位,一个int)反正。

No, there is no benefit. The short will probably end up taking a full register (which is 32 bits, an int) anyway.

在IDE中输入额外的两个字母也会浪费你的时间。 (那是一个笑话)。

You will lose hours typing the extra two letters in the IDE, too. (That was a joke).

这篇关于在...循环中使用short而不是int的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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