/////////////////////////////////////////////////////////////////////// // Listing 8-26 public int Run() { // Cleanup everything if (true) { GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); } Normal normal = new Normal(); Pinned onlyPinned = new Pinned(); GCHandle handle = GCHandle.Alloc(onlyPinned, GCHandleType.Pinned); ObjectWithStatic obj = new ObjectWithStatic(); Console.WriteLine(ObjectWithStatic.StaticField); Marked strong = new Marked(); GCHandle strongHandle = GCHandle.Alloc(strong, GCHandleType.Normal); string literal = "Hello world!"; GCHandle literalHandle = GCHandle.Alloc(literal, GCHandleType.Normal); Console.ReadLine(); GC.KeepAlive(obj); handle.Free(); literalHandle.Free(); strongHandle.Free(); return(0); }
public JsonValue ToJson(JsonSerializer serializer) { var json = new JsonObject(); Id.Serialize(json, serializer, "id"); Name.Serialize(json, serializer, "name"); Desc.Serialize(json, serializer, "desc"); Closed.Serialize(json, serializer, "closed"); Pinned.Serialize(json, serializer, "pinned"); Starred.Serialize(json, serializer, "starred"); Subscribed.Serialize(json, serializer, "subscribed"); Organization.SerializeId(json, "idOrganization"); BoardSource.SerializeId(json, "idBoardSource"); // Don't serialize the Preferences collection because Trello wants individual properties. if (Prefs != null) { Prefs.PermissionLevel.Serialize(json, serializer, "prefs/permissionLevel"); Prefs.SelfJoin.Serialize(json, serializer, "prefs/selfJoin"); Prefs.CardCovers.Serialize(json, serializer, "prefs/cardCovers"); Prefs.Invitations.Serialize(json, serializer, "prefs/invitations"); Prefs.Voting.Serialize(json, serializer, "prefs/voting"); Prefs.Comments.Serialize(json, serializer, "prefs/comments"); Prefs.CardAging.Serialize(json, serializer, "prefs/cardAging"); Prefs.CalendarFeed.Serialize(json, serializer, "prefs/calendarFeedEnabled "); Prefs.Background.Serialize(json, serializer, "prefs/background"); } return(json); }
/// <summary> /// Returns true if DesignerCommentBean instances are equal /// </summary> /// <param name="input">Instance of DesignerCommentBean to be compared</param> /// <returns>Boolean</returns> public bool Equals(DesignerCommentBean input) { if (input == null) { return(false); } return (( Text == input.Text || (Text != null && Text.Equals(input.Text)) ) && ( Pinned == input.Pinned || (Pinned != null && Pinned.Equals(input.Pinned)) ) && ( W == input.W || (W != null && W.Equals(input.W)) ) && ( H == input.H || (H != null && H.Equals(input.H)) )); }
public unsafe int Run() { // Cleanup everything if (true) { GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); } Console.WriteLine("Creating objects layout"); for (int i = 0; i < NumberOfPairs; ++i) { var pinned = new Pinned(); GCHandle handle = GCHandle.Alloc(pinned, GCHandleType.Pinned); list.Add(pinned); list.Add(new Marked()); handles.Add(handle); } Console.WriteLine("Just before blocking compacting GC"); Console.ReadLine(); GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); Console.WriteLine("After GC..."); Console.WriteLine(GC.GetGeneration(list[0])); Console.WriteLine(GC.GetGeneration(list[list.Count - 1])); Console.ReadLine(); return(list.Count); }
public void SetPinnedState(object forItem, bool isPinned) { var itemId = UniqueIdProvider.GetUniqueId(forItem); if (!_pinnedStateDictionary.ContainsKey(itemId)) { _pinnedStateDictionary.Add(itemId, false); } bool hasPinnedStateChanged = _pinnedStateDictionary[itemId] != isPinned; _pinnedStateDictionary[itemId] = isPinned; if (!hasPinnedStateChanged) { return; } if (isPinned) { Pinned?.Invoke(forItem); } else { Unpinned?.Invoke(forItem); } }
public void Free() { if (mPin != null) { mPin.Free(); mPin = null; } }
static void AssignReferences (PinList l, Pinned[] objs) { int i = 0; int n = objs.Length; while (l != null) { l.reference = objs [i++ % n]; l = l.next; } }
internal QueryFilterEmbedded Clone() => new QueryFilterEmbedded { Indentation = Indentation, GroupOperation = GroupOperation, IsGroup = IsGroup, Pinned = Pinned?.Clone(), Token = Token?.Clone(), Operation = Operation, ValueString = ValueString, };
//BIOQUIRK: This junk should ideally be handled by a source generator or something // (If it does get handled by a source generator it also needs to be threadsafe, which this is not.) public WheelCCDContactModifyCallback() { if (VTable.IsDefault) { VTable = new PxCCDContactModifyCallback.VirtualMethodTable() { onCCDContactModify = &onCCDContactModify, //BIOQUIRK: Method is missing so vtable entry is untyped __DeletingDestructorPointer = (delegate * unmanaged[Cdecl] < PxCCDContactModifyCallback *, void >) & Destructor }; } Base = new() { VirtualMethodTablePointer = VTable }; }
//BIOQUIRK: This junk should ideally be handled by a source generator or something // (If it does get handled by a source generator it also needs to be threadsafe, which this is not.) public TriggersFilterCallback() { if (VTable.IsDefault) { VTable = new PxSimulationFilterCallback.VirtualMethodTable() { pairFound = &pairFound, pairLost = &pairLost, statusChange = &statusChange, //BIOQUIRK: Method is missing so vtable entry is untyped __DeletingDestructorPointer = (delegate * unmanaged[Cdecl] < PxSimulationFilterCallback *, void >) & Destructor }; } Base = new() { VirtualMethodTablePointer = VTable }; }
static Pinned Work (PinList list, Pinned[] objs, int i) { if (i >= objs.Length) { for (int j = 0; j < 10; ++j) { MakeList (1 << 19); AssignReferences (list, objs); } return null; } else { Pinned obj = new Pinned (); objs [i] = obj; Pinned dummy = Work (list, objs, i + 1); return obj != dummy ? obj : dummy; // to keep obj alive } }
static Pinned Work(PinList list, Pinned[] objs, int i) { if (i >= objs.Length) { for (int j = 0; j < 10; ++j) { MakeList(list_size >> 5); AssignReferences(list, objs); } return(null); } else { Pinned obj = new Pinned(); objs [i] = obj; Pinned dummy = Work(list, objs, i + 1); return(obj != dummy ? obj : dummy); // to keep obj alive } }
public XElement ToXml(IToXmlContext ctx) { if (this.GroupOperation.HasValue) { return(new XElement("Filter", new XAttribute("Indentation", Indentation), new XAttribute("GroupOperation", GroupOperation), Token == null ? null ! : new XAttribute("Token", Token.Token.FullKey()), Pinned?.ToXml(ctx) !)); } else { return(new XElement("Filter", new XAttribute("Indentation", Indentation), new XAttribute("Token", Token !.Token.FullKey()), new XAttribute("Operation", Operation !), ValueString == null ? null ! : new XAttribute("Value", ValueString), Pinned?.ToXml(ctx) !)); } }
//BIOQUIRK: This junk should ideally be handled by a source generator or something // (If it does get handled by a source generator it also needs to be threadsafe, which this is not.) public ContactReportCallback() { if (VTable.IsDefault) { VTable = new PxSimulationEventCallback.VirtualMethodTable() { onConstraintBreak = &onConstraintBreak, onWake = &onWake, onSleep = &onSleep, onContact = &onContact, onTrigger = &onTrigger, onAdvance = &onAdvance, __DeletingDestructorPointer = &Destructor }; } Base = new() { VirtualMethodTablePointer = VTable }; }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Text != null) { hashCode = hashCode * 59 + Text.GetHashCode(); } if (Pinned != null) { hashCode = hashCode * 59 + Pinned.GetHashCode(); } if (W != null) { hashCode = hashCode * 59 + W.GetHashCode(); } if (H != null) { hashCode = hashCode * 59 + H.GetHashCode(); } return(hashCode); } }
static void Benchmark(PinList list, int n) { Pinned[] objs = new Pinned [n]; Work(list, objs, 0); }
public override string ToString() { return(string.Format("{0}|{1}", Pinned.ToString(), FullPath)); }
private void Release() { Event?.Set(); Event?.Dispose(); Pinned?.Free(); }
static void Benchmark (PinList list, int n) { Pinned[] objs = new Pinned [n]; Work (list, objs, 0); }
public IntPtr Pin() { Free(); mPin = new Pinned(mOptions); return mPin.Address; }