源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 regels
1.5 KiB

using System;
using UnityEditor.MemoryProfiler;
namespace MemoryProfilerWindow
{
static class ArrayTools
{
public static int ReadArrayLength(MemorySection[] heap, UInt64 address, TypeDescription arrayType, VirtualMachineInformation virtualMachineInformation)
{
var bo = heap.Find(address, virtualMachineInformation);
var bounds = bo.Add(virtualMachineInformation.arrayBoundsOffsetInHeader).ReadPointer();
if (bounds == 0)
return bo.Add(virtualMachineInformation.arraySizeOffsetInHeader).ReadInt32();
var cursor = heap.Find(bounds, virtualMachineInformation);
int length = 1;
for (int i = 0; i != arrayType.arrayRank; i++)
{
length *= cursor.ReadInt32();
cursor = cursor.Add(8);
}
return length;
}
public static int ReadArrayObjectSizeInBytes(MemorySection[] heap, UInt64 address, TypeDescription arrayType, TypeDescription[] typeDescriptions, VirtualMachineInformation virtualMachineInformation)
{
var arrayLength = ArrayTools.ReadArrayLength(heap, address, arrayType, virtualMachineInformation);
var elementType = typeDescriptions[arrayType.baseOrElementTypeIndex];
var elementSize = elementType.isValueType ? elementType.size : virtualMachineInformation.pointerSize;
return virtualMachineInformation.arrayHeaderSize + elementSize * arrayLength;
}
}
}