public void GetConnectionsCount(PackedConnection.Kind kind, int index, out int referencesCount, out int referencedByCount) { referencesCount = 0; referencedByCount = 0; var key = ComputeConnectionKey(kind, index); List <PackedConnection> refs; if (m_ConnectionsFrom.TryGetValue(key, out refs)) { referencesCount = refs.Count; } List <PackedConnection> refBy; if (m_ConnectionsTo.TryGetValue(key, out refBy)) { referencedByCount = refBy.Count; } }
void GetConnectionsInternal(PackedConnection.Kind kind, int index, List <PackedConnection> references, List <PackedConnection> referencedBy) { var key = ComputeConnectionKey(kind, index); if (references != null) { List <PackedConnection> refs; if (m_ConnectionsFrom.TryGetValue(key, out refs)) { references.AddRange(refs); } } if (referencedBy != null) { List <PackedConnection> refsBy; if (m_ConnectionsTo.TryGetValue(key, out refsBy)) { referencedBy.AddRange(refsBy); } } }
/// <summary> /// Add a connection between two objects, such as a connection from a native object to its managed counter-part. /// </summary> /// <param name="fromKind">The connection kind, that is pointing to another object.</param> /// <param name="fromIndex">An index into a snapshot array, depending on specified fromKind. If the kind would be 'Native', then it must be an index into the snapshot.nativeObjects array.</param> /// <param name="toKind">The connection kind, to which the 'from' object is pointing to.</param> /// <param name="toIndex">An index into a snapshot array, depending on the specified toKind. If the kind would be 'Native', then it must be an index into the snapshot.nativeObjects array.</param> public void AddConnection(PackedConnection.Kind fromKind, int fromIndex, PackedConnection.Kind toKind, int toIndex) { var connection = new PackedConnection { fromKind = fromKind, from = fromIndex, toKind = toKind, to = toIndex }; if (connection.fromKind != PackedConnection.Kind.None && connection.from != -1) { var key = ComputeConnectionKey(connection.fromKind, connection.from); List <PackedConnection> list; if (!m_ConnectionsFrom.TryGetValue(key, out list)) { m_ConnectionsFrom[key] = list = new List <PackedConnection>(1); // Capacity=1 to reduce memory usage on HUGE memory snapshots } list.Add(connection); } if (connection.toKind != PackedConnection.Kind.None && connection.to != -1) { if (connection.to < 0) { connection.to = -connection.to; } var key = ComputeConnectionKey(connection.toKind, connection.to); List <PackedConnection> list; if (!m_ConnectionsTo.TryGetValue(key, out list)) { m_ConnectionsTo[key] = list = new List <PackedConnection>(1); // Capacity=1 to reduce memory usage on HUGE memory snapshots } list.Add(connection); } }
UInt64 ComputeConnectionKey(PackedConnection.Kind kind, int index) { var value = (UInt64)(((int)kind << 50) + index); return(value); }