源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

35 行
1.5 KiB

  1. using System;
  2. using UnityEditor.MemoryProfiler;
  3. namespace MemoryProfilerWindow
  4. {
  5. static class ArrayTools
  6. {
  7. public static int ReadArrayLength(MemorySection[] heap, UInt64 address, TypeDescription arrayType, VirtualMachineInformation virtualMachineInformation)
  8. {
  9. var bo = heap.Find(address, virtualMachineInformation);
  10. var bounds = bo.Add(virtualMachineInformation.arrayBoundsOffsetInHeader).ReadPointer();
  11. if (bounds == 0)
  12. return bo.Add(virtualMachineInformation.arraySizeOffsetInHeader).ReadInt32();
  13. var cursor = heap.Find(bounds, virtualMachineInformation);
  14. int length = 1;
  15. for (int i = 0; i != arrayType.arrayRank; i++)
  16. {
  17. length *= cursor.ReadInt32();
  18. cursor = cursor.Add(8);
  19. }
  20. return length;
  21. }
  22. public static int ReadArrayObjectSizeInBytes(MemorySection[] heap, UInt64 address, TypeDescription arrayType, TypeDescription[] typeDescriptions, VirtualMachineInformation virtualMachineInformation)
  23. {
  24. var arrayLength = ArrayTools.ReadArrayLength(heap, address, arrayType, virtualMachineInformation);
  25. var elementType = typeDescriptions[arrayType.baseOrElementTypeIndex];
  26. var elementSize = elementType.isValueType ? elementType.size : virtualMachineInformation.pointerSize;
  27. return virtualMachineInformation.arrayHeaderSize + elementSize * arrayLength;
  28. }
  29. }
  30. }