更快的方式来转换字节数组为int [英] Faster way to convert byte array to int

查看:140
本文介绍了更快的方式来转换字节数组为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更快的方式比的 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.

这篇关于更快的方式来转换字节数组为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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