更快的方式来转换字节数组为int更快、数组、字节、方式

2023-09-03 22:52:50 作者:佯装、幸福

有没有更快的方式比的 BitConverter.ToInt32 以字节数组转换为int值?

Is there a faster way than BitConverter.ToInt32 to convert a byte array to an int value?

推荐答案

如果我没有记错,这实现使用不安全code(处理一个字节*为int *),所以这将是很难被击败,但另一种方法是转移。

If I remember correctly, that implementation uses unsafe code (treating a byte* as an int*), so it will be hard to beat, but the other alternative is shifting.

不过,从在这方面的工作很多,是这样的话不可能是一个真正的瓶颈是不相关的。 I / O是主要的问题,一般。

However, from lots of work in this area, this is so unlikely to be a genuine bottleneck as to be irrelevant. I/O is the main issue, typically.

的GetBytes(int)的,然而,是的更昂贵(在高容量)由于阵列/堆分配

GetBytes(int), however, is more expensive (in high volume) due to array / heap allocation.

 
精彩推荐
图片推荐