|
|
- using System;
- using UnityEditor.MemoryProfiler;
- using UnityEngine;
-
- namespace MemoryProfilerWindow
- {
- internal struct BytesAndOffset
- {
- public byte[] bytes;
- public int offset;
- public int pointerSize;
- public bool IsValid { get { return bytes != null; }}
-
- public UInt64 ReadPointer()
- {
- if (pointerSize == 4)
- return BitConverter.ToUInt32(bytes, offset);
- if (pointerSize == 8)
- return BitConverter.ToUInt64(bytes, offset);
- throw new ArgumentException("Unexpected pointersize: " + pointerSize);
- }
-
- public Int32 ReadInt32()
- {
- return BitConverter.ToInt32(bytes, offset);
- }
-
- public Int64 ReadInt64()
- {
- return BitConverter.ToInt64(bytes, offset);
- }
-
- public BytesAndOffset Add(int add)
- {
- return new BytesAndOffset() {bytes = bytes, offset = offset + add, pointerSize = pointerSize};
- }
-
- public void WritePointer(UInt64 value)
- {
- for (int i = 0; i < pointerSize; i++)
- {
- bytes[i + offset] = (byte)value;
- value >>= 8;
- }
- }
-
- public BytesAndOffset NextPointer()
- {
- return Add(pointerSize);
- }
- }
- }
|