private static void SnapshotFinished(string path, bool result)
        {
            if (result)
            {
                Profiling.Memory.Experimental.PackedMemorySnapshot snapshot = Profiling.Memory.Experimental.PackedMemorySnapshot.Load(path);

                var oldSnapshot = new PackedMemorySnapshot(snapshot);
                snapshot.Dispose();
                File.Delete(path);

                OnSnapshotReceived(oldSnapshot);
            }
            else
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                OnSnapshotReceived(null);
            }
        }
        public PackedMemorySnapshot(Profiling.Memory.Experimental.PackedMemorySnapshot snapshot)
        {
            int cacheCapacity = 128;

            string[] cacheString  = new string[cacheCapacity];
            string[] cacheString2 = new string[cacheCapacity];
            int[]    cacheInt     = new int[cacheCapacity];
            int[]    cacheInt2    = new int[cacheCapacity];
            int[]    cacheInt3    = new int[cacheCapacity];
            ulong[]  cacheULong   = new ulong[cacheCapacity];
            ulong[]  cacheULong2  = new ulong[cacheCapacity];
            byte[][] cacheBytes   = new byte[cacheCapacity][];

            m_NativeTypes = new PackedNativeType[snapshot.nativeTypes.GetNumEntries()];
            {
                for (int offset = 0; offset < m_NativeTypes.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_NativeTypes.Length - offset, cacheCapacity);

                    snapshot.nativeTypes.typeName.GetEntries((uint)offset, size, ref cacheString);
                    snapshot.nativeTypes.nativeBaseTypeArrayIndex.GetEntries((uint)offset, size, ref cacheInt);

                    for (uint i = 0; i < size; i++)
                    {
                        m_NativeTypes[offset + i] = new PackedNativeType(cacheString[i], cacheInt[i]);
                    }
                }
            }

            m_NativeObjects = new PackedNativeUnityEngineObject[snapshot.nativeObjects.GetNumEntries()];
            {
                UnityEditor.Profiling.Memory.Experimental.ObjectFlags[] cacheObjectFlags = new UnityEditor.Profiling.Memory.Experimental.ObjectFlags[cacheCapacity];
                UnityEngine.HideFlags[] cacheHideFlags = new UnityEngine.HideFlags[cacheCapacity];

                for (int offset = 0; offset < m_NativeObjects.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_NativeObjects.Length - offset, cacheCapacity);

                    snapshot.nativeObjects.objectName.GetEntries((uint)offset, size, ref cacheString);
                    snapshot.nativeObjects.instanceId.GetEntries((uint)offset, size, ref cacheInt);
                    snapshot.nativeObjects.size.GetEntries((uint)offset, size, ref cacheULong);
                    snapshot.nativeObjects.nativeTypeArrayIndex.GetEntries((uint)offset, size, ref cacheInt2);
                    snapshot.nativeObjects.hideFlags.GetEntries((uint)offset, size, ref cacheHideFlags);
                    snapshot.nativeObjects.flags.GetEntries((uint)offset, size, ref cacheObjectFlags);
                    snapshot.nativeObjects.nativeObjectAddress.GetEntries((uint)offset, size, ref cacheULong2);

                    for (uint i = 0; i < size; i++)
                    {
                        m_NativeObjects[offset + i] = new PackedNativeUnityEngineObject(
                            cacheString[i],
                            cacheInt[i],
                            (int)cacheULong[i],
                            cacheInt2[i],
                            cacheHideFlags[i],
                            (PackedNativeUnityEngineObject.ObjectFlags)cacheObjectFlags[i],
                            (long)cacheULong2[i]);
                    }
                }
            }

            m_GCHandles = new PackedGCHandle[snapshot.gcHandles.GetNumEntries()];
            {
                for (int offset = 0; offset < m_GCHandles.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_GCHandles.Length - offset, cacheCapacity);

                    snapshot.gcHandles.target.GetEntries((uint)offset, size, ref cacheULong);

                    for (uint i = 0; i < size; i++)
                    {
                        m_GCHandles[offset + i] = new PackedGCHandle((UInt64)cacheULong[i]);
                    }
                }
            }

            m_Connections = new Connection[snapshot.connections.GetNumEntries()];
            {
                for (int offset = 0; offset < m_Connections.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_Connections.Length - offset, cacheCapacity);

                    snapshot.connections.from.GetEntries((uint)offset, (uint)size, ref cacheInt);
                    snapshot.connections.to.GetEntries((uint)offset, (uint)size, ref cacheInt2);

                    for (uint i = 0; i < size; i++)
                    {
                        m_Connections[offset + i] = new Connection(cacheInt[i], cacheInt2[i]);
                    }
                }
            }

            m_ManagedHeapSections = new MemorySection[snapshot.managedHeapSections.GetNumEntries()];
            {
                for (int offset = 0; offset < m_ManagedHeapSections.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_ManagedHeapSections.Length - offset, cacheCapacity);

                    snapshot.managedHeapSections.startAddress.GetEntries((uint)offset, (uint)size, ref cacheULong);
                    snapshot.managedHeapSections.bytes.GetEntries((uint)offset, (uint)size, ref cacheBytes);

                    for (uint i = 0; i < size; i++)
                    {
                        m_ManagedHeapSections[offset + i] = new MemorySection(cacheBytes[i], (UInt64)cacheULong[i]);
                    }
                }
            }

            m_TypeDescriptions = new TypeDescription[snapshot.typeDescriptions.GetNumEntries()];
            {
                UnityEditor.Profiling.Memory.Experimental.TypeFlags[] cacheFlags = new UnityEditor.Profiling.Memory.Experimental.TypeFlags[cacheCapacity];
                int[][]  cacheRange       = new int[cacheCapacity][];
                string[] cacheSmallString = new string[1];
                int[]    cacheSmallInt    = new int[1];
                int[]    cacheSmallInt2   = new int[1];
                bool[]   cacheSmallBool   = new bool[1];

                for (int offset = 0; offset < m_TypeDescriptions.Length; offset += cacheCapacity)
                {
                    uint size = (uint)Math.Min(m_TypeDescriptions.Length - offset, cacheCapacity);
                    snapshot.typeDescriptions.typeDescriptionName.GetEntries((uint)offset, (uint)size, ref cacheString);
                    snapshot.typeDescriptions.assembly.GetEntries((uint)offset, (uint)size, ref cacheString2);
                    snapshot.typeDescriptions.fieldIndices.GetEntries((uint)offset, (uint)size, ref cacheRange);
                    snapshot.typeDescriptions.staticFieldBytes.GetEntries((uint)offset, (uint)size, ref cacheBytes);
                    snapshot.typeDescriptions.baseOrElementTypeIndex.GetEntries((uint)offset, (uint)size, ref cacheInt);
                    snapshot.typeDescriptions.size.GetEntries((uint)offset, (uint)size, ref cacheInt2);
                    snapshot.typeDescriptions.typeInfoAddress.GetEntries((uint)offset, (uint)size, ref cacheULong);
                    snapshot.typeDescriptions.typeIndex.GetEntries((uint)offset, (uint)size, ref cacheInt3);
                    snapshot.typeDescriptions.flags.GetEntries((uint)offset, (uint)size, ref cacheFlags);

                    for (int i = 0; i < size; ++i)
                    {
                        FieldDescription[] fieldDescription = new FieldDescription[cacheRange[i].Length];

                        for (uint j = 0; j < cacheRange[i].Length; j++)
                        {
                            snapshot.fieldDescriptions.fieldDescriptionName.GetEntries((uint)cacheRange[i][j], 1, ref cacheSmallString);
                            snapshot.fieldDescriptions.offset.GetEntries((uint)cacheRange[i][j], 1, ref cacheSmallInt);
                            snapshot.fieldDescriptions.typeIndex.GetEntries((uint)cacheRange[i][j], 1, ref cacheSmallInt2);
                            snapshot.fieldDescriptions.isStatic.GetEntries((uint)cacheRange[i][j], 1, ref cacheSmallBool);

                            fieldDescription[j] = new FieldDescription(cacheSmallString[0], cacheSmallInt[0], cacheSmallInt2[0], cacheSmallBool[0]);
                        }

                        m_TypeDescriptions[offset + i] = new TypeDescription(
                            cacheString[i],
                            cacheString2[i],
                            fieldDescription,
                            cacheBytes[i],
                            cacheInt[i],
                            cacheInt2[i],
                            (UInt64)cacheULong[i],
                            cacheInt3[i],
                            (TypeDescription.TypeFlags)cacheFlags[i]);
                    }
                }
            }

            m_VirtualMachineInformation = new VirtualMachineInformation(snapshot.virtualMachineInformation);
        }