2014-05-10 3 views
1

음, 다양한 데이터 "바이트"를 "long"으로 변환하려고합니다. 그리고 아주 느린 것 같다 ...느린 처리 ​​

코드 :

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 

누구든지 조언 해결책을 가지고?

+2

왜 이것이 느리다 고 생각합니까? – Enigmativity

답변

0

내가 볼 수있는 한 가지 문제점은 긴 값을 읽을 때마다 buff.ToArray (으)로 전화하고 있다는 것입니다. ToArray 메서드는 매번 버퍼 복사본을 만듭니다. 배열 처리를 시작하기 전에 ToArray에 전화하여 BitConverter.ToInt64 메서드를 호출 할 때 배열 인스턴스를 사용해야합니다.

관련 문제