Vb.net 慢处理
我正在尝试将各种数据字节转换为长字节。 而且看起来很慢 代码: 转换器:Vb.net 慢处理,vb.net,for-loop,bitconverter,Vb.net,For Loop,Bitconverter,我正在尝试将各种数据字节转换为长字节。 而且看起来很慢 代码: 转换器: Public Function ReadLong(Optional ByVal peek As Boolean = True) As Long If Buff.Count > readpos Then 'check to see if this passes the byte count Dim ret As Long = BitConverter.ToInt64(Buff.ToArray,
Public Function ReadLong(Optional ByVal peek As Boolean = True) As Long
If Buff.Count > readpos Then 'check to see if this passes the byte count
Dim ret As Long = BitConverter.ToInt64(Buff.ToArray, readpos)
If peek And Buff.Count > readpos Then
readpos += 8
End If
Return ret
Else
Throw New Exception("Byte Buffer Past Limit!") 'past byte count throw a new exception
End If
End Function
有人有什么建议或解决方案吗?我看到的一个问题是,每次读取长值时,都会调用buff.ToArray。ToArray方法每次都会复制缓冲区。您应该在开始处理映射之前调用ToArray,并在调用BitConverter.ToInt64方法时使用数组实例。您认为这是什么原因造成的?
Public Function ReadLong(Optional ByVal peek As Boolean = True) As Long
If Buff.Count > readpos Then 'check to see if this passes the byte count
Dim ret As Long = BitConverter.ToInt64(Buff.ToArray, readpos)
If peek And Buff.Count > readpos Then
readpos += 8
End If
Return ret
Else
Throw New Exception("Byte Buffer Past Limit!") 'past byte count throw a new exception
End If
End Function