public void AddingAddressOutsideHeap_ForTheSecondTime_ReturnsFalse() { var set = new ObjectAddressSet(GetTestHeapIndex()); Assert.That(set.Add(0x00400000), Is.True); Assert.That(set.Add(0x00400000), Is.False); }
public IEnumerable <IClrObject> ExploreFromRoots() { var reader = new ClrObjectReader(); foreach (var root in heap.EnumerateRoots()) { if (root.Object == 0) { continue; } if (!visited.Add(root.Object)) { continue; } if (root.Kind == GCRootKind.Finalizer) { continue; } if (root.Address == 0) { continue; } if (!reader.IsValidObjectType(root.Type)) { continue; } yield return(reader.ReadGCRoot(root)); CollectChildren(root.Type, root.Object); } while (pending.Count > 0) { var address = pending.Pop(); if (!visited.Add(address)) { continue; } var type = heap.GetObjectType(address); if (!reader.IsValidObjectType(type)) { continue; } yield return(reader.ReadFromAddress(type, address)); CollectChildren(type, address); } }
public void CollectionIsFastEnoughForAMillionAddresses(int seed) { var random = new Random(seed); var addresses = Enumerable.Range(0, 1000000).Select(i => (ulong)random.Next(0x00100000, 0x28000000)).ToArray(); var collection = new ObjectAddressSet(GetTestHeapIndex()); var swObjectAddressSet = Stopwatch.StartNew(); foreach (var address in addresses) { collection.Add(address); } foreach (var address in addresses) { collection.Contains(address); } swObjectAddressSet.Stop(); var hashSet = new HashSet <ulong>(); var swHashSet = Stopwatch.StartNew(); foreach (var address in addresses) { hashSet.Add(address); } foreach (var address in addresses) { hashSet.Contains(address); } swHashSet.Stop(); Trace.WriteLine($"ObjectAddressSet: {swObjectAddressSet.Elapsed}"); Trace.WriteLine($"HashSet<ulong>: {swHashSet.Elapsed}"); }
public void AddingAddressInsideHeap_ForTheFirstTime_ReturnsTrue() { var set = new ObjectAddressSet(GetTestHeapIndex()); Assert.That(set.Add(0x00200000), Is.True); }