1

好吧,我正在尝试将各种数据“字节”转换为“长”。而且它似乎很慢......

代码:

    For X = 0 To Map.MaxX
        For Y = 0 To Map.MaxY
            Map.Tile(X, Y).Data1 = Buffer.ReadLong
            Map.Tile(X, Y).Data2 = Buffer.ReadLong
            Map.Tile(X, Y).Data3 = Buffer.ReadLong
            Map.Tile(X, Y).DirBlock = Buffer.ReadLong
            ReDim Map.Tile(X, Y).Layer(0 To MapLayer.Layer_Count - 1)
            For i = 0 To MapLayer.Layer_Count - 1
                Map.Tile(X, Y).Layer(i).tileset = Buffer.ReadLong
                Map.Tile(X, Y).Layer(i).X = Buffer.ReadLong
                Map.Tile(X, Y).Layer(i).Y = Buffer.ReadLong
            Next
            Map.Tile(X, Y).Type = Buffer.ReadLong
        Next
    Next

转换器:

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

有人有提示或解决方案吗?

4

1 回答 1

0

我可以看到的一个问题是buff.ToArray每次读取长值时都会调用。该ToArray方法每次都会复制缓冲区。您应该在开始处理地图之前调用,并在调用方法ToArray时使用数组实例。BitConverter.ToInt64

于 2014-05-10T09:33:27.113 回答