在.NET字节与INT性能字节、性能、NET、INT

2023-09-06 13:09:13 作者:好网名都被猪拱了

在pre-.NET世界里,我一直认为int是不是字节更快,因为这是怎样的处理器的作品。

In pre-.NET world I always assumed that int is faster than byte since this is how processor works.

现在它的使用为int的事情的习惯,即使字节可以工作,例如,当一个字节是存储在数据库中

Now it's matter habit of using int even when bytes could work, for example when byte is what is stored in database

问:.NET如何处理字节型与从性能/内存来看INT

Question: How .NET handles byte type versus int from point view of performance/memory.

更新: 感谢您的输入。不幸的是,没有人真正回答了这个问题。如何.NET处理字节与int类型。

Update: Thanks for the input. Unfortunately, nobody really answered the question. How .NET handles byte vs. int.

如果没有在性能上没有什么区别,那我怎么样chills42所说的那样: INT的算术 字节的二进制 我将继续这样做。

And if there is no difference in performance, then I like how chills42 put it: int for arithmetics bytes for binary Which I will continue to do.

推荐答案

好了,我刚打开反汇编窗口。没有什么存在,但常规的MOV字节

OK, I just opened disassembly window. There is nothing there but regular "mov byte"

所以,.NET / CLR没有任何东西把它添加。而反对的int值做了所有的算术运算,所以字节之间的差异和int那里。

So, .NET/CLR does not add anything to this. And all arithmetic operations done against int values, so no difference between bytes and int there.