我应该使用字节或者int? [英] Should I use byte or int?

查看:106
本文介绍了我应该使用字节或者int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得读过的地方,最好是(在性能方面)使用的Int32,即使你只需要一个字节。它适用于(据说)只有在那里你不关心存储情况。这是有效的?

I recall having read somewhere that it is better (in terms of performance) to use Int32, even if you only require Byte. It applies (supposedly) only to cases where you do not care about the storage. Is this valid?

例如,我需要一个变量,将举行一周中的一天。难道我

For example, I need a variable that will hold a day of week. Do I

int dayOfWeek;

byte dayOfWeek;

修改
伙计们,我知道星期几枚举。现在的问题是别的东西。

EDIT: Guys, I am aware of DayOfWeek enum. The question is about something else.

推荐答案

通常是的,一个32位整数将执行稍好,因为它已经被正确的本地CPU指令对齐。当你真正需要存储大小的东西,你应该只使用较小尺寸的数值类型。

Usually yes, a 32 bit integer will perform slightly better because it is already properly aligned for native CPU instructions. You should only use a smaller sized numeric type when you actually need to store something of that size.

这篇关于我应该使用字节或者int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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