// This method demonstrates the unbalanced nature of ReRegisterForFinalize // and SuppressFinalize. The main point is if your code makes multiple // calls to ReRegisterForFinalize (without intervening calls to // SuppressFinalize) the Finalize method may get called multiple times. private static void FinalizationQDemo() { Display(0, "\n\nDemo start: Suppressing and ReRegistering for Finalize.", +1); // Since this object has a Finalize method, a reference to the object // will be added to the finalization queue. BaseObj obj = new BaseObj("Finalization Queue"); // Add another 2 references onto the finalization queue // NOTE: Don't do this in a normal app. This is only for demo purposes. GC.ReRegisterForFinalize(obj); GC.ReRegisterForFinalize(obj); // There are now 3 references to this object on the finalization queue. // Set a bit flag on this object indicating that it should NOT be finalized. GC.SuppressFinalize(obj); // There are now 3 references to this object on the finalization queue. // If the object were unreachable, the 1st call to this object's Finalize // method will be discarded but the 2nd & 3rd calls to Finalize will execute. // Sets the same bit effectively doing nothing! GC.SuppressFinalize(obj); obj = null; // Remove the strong reference to the object. // Force a GC so that the object gets finalized Collect(); // NOTE: Finalize is called twice because only the 1st call is suppressed! WaitForFinalizers(); Display(-1, "Demo stop: Suppressing and ReRegistering for Finalize.", 0); }
void DoSave(object parameter) { var ctl = parameter as ContentControl; var o = ctl.Content as BaseObjDto; if (o.Id == 0) { BaseObj objNew = null; objNew = ObjFromDto(o, objNew); _bll.Add(objNew); } else { var objExisting = _bll.GetItemById(o.Id); ModuleAModule.TheMapper.Map(o, objExisting); } _bll.Flush(); _bll = _container.Resolve <IBLL>(new ResolverOverride[] { new ParameterOverride("filePath", StoragePath) }); var lst = _bll.GetFiltered("", 10, _currentOffset); PopulateFilteredList(lst); }
public static int Main(String[] args) { // Environment.ExitCode = 1; Display("To fully understand this sample, you should step through the"); Display("code in the debugger while monitoring the output generated.\n"); Display("NOTE: The demos in this application assume that no garbage"); Display(" collections occur naturally. To ensure this, the sample"); Display(" objects are small in size and few are allocated.\n"); Display("Main thread's hash code: " + Thread.CurrentThread.GetHashCode()); Introduction(); // GC introduction ResurrectionDemo(); // Demos object resurrection DisposeDemo(); // Demos the use of Dispose & Finalize FinalizationQDemo(); // Demos the use of SuppressFinalize & ReRegisterForFinalize GenerationDemo(); // Demos GC generations WeakRefDemo(false); // Demos WeakReferences without resurrection tracking WeakRefDemo(true); // Demos WeakReferences with resurrection tracking // Demos Finalize on Shutdown symantics (this demo is inline) Display(0, "\n\nDemo start: Finalize on shutdown.", +1); // When Main returns, obj will have its Finalize method called. BaseObj obj = new BaseObj("Shutdown"); // This is the last line of code executed before the application terminates. Display(-1, "Demo stop: Finalize on shutdown (application is now terminating)", 0); return(100); }
private GameObject GetPrefab(BaseObj item) { string GetName() { if (item is Player) { return("Player"); } if (item is Floor) { return("Floor"); } if (item is Box) { return("Box"); } if (item is Goal goal) { if (goal.isPlayer) { return("Goal-Player"); } return("Goal-Box"); } return(""); } var obj = Resources.Load <GameObject>("Prefabs/" + GetName()); return(obj); }
public void Add(Student student) { BaseObj.Push(student.BasePerson); ToStringValues.Push(student.ToString()); PersonStudent.Add(student.BasePerson, student); StringStudent.Add(student.ToString(), student); }
public void HideEditorWindow() { instanceEditorWindow.SetActive(false); Destroy(instanceTargetObj); BaseObj.SetMouseEvent(MouseEvent.None); GeneralController.instance.SetCurtain(false); }
public void SetData(BaseObj originObj, EditorBaseObj targetObj) { this.targetObj = targetObj; this.originObj = originObj; targetObj.SetData(originObj, PartsOfFrameObj); targetObj.SetCallback(CollorArrowPointerChangePos); foreach (var item in colorButton) { item.SendColorCallback = targetObj.GetColorCallback; } foreach (var item in newLineButton) { item.SetData(targetObj, LineEditButtonChangePos); } foreach (var item in delLineButton) { item.SetData(targetObj, LineEditButtonChangePos); } foreach (var item in angleButton) { item.SetData(targetObj, AngleChange); } foreach (var item in scaleButton) { item.SetData(originObj, ScaleChange); } ReseLineEditButtonPos(); InitializeAngle(); InitializeScale(); if (originObj.type == ObjType.Frame && originObj.lineNum != defaultLineNum) { int difference = originObj.lineNum - defaultLineNum; if (difference > 0) { for (int count = 0; count < difference; count++) { LineEditButtonChangePos(true); } } else if (difference < 0) { difference = Mathf.FloorToInt(Mathf.Abs((float)difference)); for (int count = 0; count < difference; count++) { LineEditButtonChangePos(false); } } } }
/// <summary> /// Первоначальная загрузка объектов до нажатия кнопки "Начать игру" /// Инициализация объектов Star /// </summary> public static void InitialLoad() { InitLists(); DiffLvl = St.MinDiffLevel; EmpireShip.DestroyedShips = 0; // Обнуляем кол-во сбитых кораблей - противников EmpireShip.CreatedShips = 0; // Обнуляем кол-во созданных кораблей - противников for (int i = 0; i < St.StarsCount; i++) { BaseObj.Add(new Star(new Point(Rand.Next(0, St.FieldWidth), Rand.Next(10, St.FieldHeight)), new Point(i % 20 - 1, 0), new Size(St.MinStarSize, St.MaxStarSize))); } }
protected override void setupExpectations() { _data = new BaseObj(); _event = PrivateEvent.Create(_data); _objectSubscriber.Expect(s => s.OnPublished(_event)); _eventWithObjectSubscriber.Expect(s => s.OnPublished(null)) .Constraints(Property.Value("Data", _data)); _eventWithBaseObjSubscriber.Expect(s => s.OnPublished(null)) .Constraints(Property.Value("Data", _data)); }
private static BaseObj ObjFromDto(BaseObjDto o, BaseObj objNew) { if (o.GetType() == typeof(NoteDto)) { objNew = ModuleAModule.TheMapper.Map <Note>(o); } if (o.GetType() == typeof(CreditCardDto)) { objNew = ModuleAModule.TheMapper.Map <CreditCard>(o); } if (o.GetType() == typeof(WebAccDto)) { objNew = ModuleAModule.TheMapper.Map <WebAcc>(o); } return(objNew); }
static public void RemoveObject(long id) { var tmpObjList = new List <ObjectsData> (); tmpObjList.AddRange(m_savedata.m_obj); ObjectsData tmpA = null; foreach (var item in tmpObjList) { if (item.id == id) { tmpA = item; } if (item.id > id) { item.id--; } } if (tmpA != null) { tmpObjList.Remove(tmpA); m_savedata.m_general.curId--; } m_savedata.m_obj = tmpObjList.ToArray(); BaseObj tmpB = null; foreach (var item in instatiatedObj) { if (item.ID == id) { tmpB = item; } if (item.ID > id) { item.ID--; } } if (tmpB != null) { instatiatedObj.Remove(tmpB); } curId--; }
public void SerializeDeserialize_ShouldPreserveValues() { var obj = new DerivedObj() { Length = 123.1, Name = "Lol123!", Lives = 7, Strength = 4.8 }; string str = BasicSerializer.Serialize(obj); BaseObj mirrorBase = BasicSerializer.Deserialize <BaseObj>(str); DerivedObj mirror = Assert.IsType <DerivedObj>(mirrorBase); Assert.Equal(obj.Length, mirror.Length); Assert.Equal(obj.Name, mirror.Name); Assert.Equal(obj.Lives, mirror.Lives); Assert.Equal(obj.Strength, mirror.Strength); }
static public void SetNewObject(ObjectsData data, BaseObj obj) { int length = m_savedata.m_obj.Length; ObjectsData[] tmpArray = new ObjectsData[length + 1]; for (int count = 0; count < length + 1; count++) { if (count == length) { tmpArray [count] = data; } else { tmpArray [count] = m_savedata.m_obj [count]; } } m_savedata.m_obj = tmpArray; instatiatedObj.Add(obj); }
public void ShowEditorWindow(BaseObj data) { linkBaseObj = data; instanceEditorWindow.SetActive(true); instanceTargetObj = Instantiate(data.gameObject) as GameObject; instanceTargetObj.transform.parent = instanceEditorWindow.transform; instanceTargetObj.transform.SetSiblingIndex(7); Vector3 screenPos = Camera.main.ScreenToWorldPoint(InnerCircle.transform.localPosition); instanceTargetObj.transform.position = InnerCircle.transform.position; instanceTargetObj.transform.localScale = new Vector3(1, 1, 1); var itemButton = instanceTargetObj.GetComponentsInChildren <Button>(); if (itemButton != null) { foreach (var item in itemButton) { item.interactable = false; } } var itemRenameButton = instanceTargetObj.GetComponentsInChildren <RenameButton>(); if (itemRenameButton != null) { foreach (var item in itemRenameButton) { Destroy(item); } } var itemButtonSupport = instanceTargetObj.GetComponentsInChildren <ButtonSupport>(); if (itemButtonSupport != null) { foreach (var item in itemButtonSupport) { Destroy(item); } } switch (data.type) { case ObjType.Frame: Destroy(instanceTargetObj.GetComponent <FrameObj>()); instanceTargetObj.AddComponent <EditorFrameObj>(); instanceEditorWindow.GetComponent <EditorWindowControll>().SetData (data, instanceTargetObj.GetComponent <EditorFrameObj>()); break; case ObjType.Triangle: Destroy(instanceTargetObj.GetComponent <TriangleObj>()); instanceTargetObj.AddComponent <EditorTriangleObj>(); instanceEditorWindow.GetComponent <EditorWindowControll>().SetData (data, instanceTargetObj.GetComponent <EditorTriangleObj>()); break; case ObjType.Text: Destroy(instanceTargetObj.GetComponent <TextObj>()); instanceTargetObj.AddComponent <EditorTextObj>(); instanceEditorWindow.GetComponent <EditorWindowControll>().SetData (data, instanceTargetObj.GetComponent <EditorTextObj>()); break; } GeneralController.instance.SetCurtain(true); }
protected override void setupExpectations() { _data = new BaseObj(); _event = new Event<BaseObj>(_data); }
public void SetData(BaseObj originObj, System.Action <Vector3> ScaleChange) { this.originObj = originObj; this.targetObj = targetObj; this.ScaleChange = ScaleChange; }
// This method demonstrates how weak references (WR) work. A WR allows // the GC to collect objects if the managed heap is low on memory. // WRs are useful to apps that have large amounts of easily-reconstructed // data that they want to keep around to improve performance. But, if the // system is low on memory, the objects can be destroyed and replaced when // the app knows that it needs it again. private static void WeakRefDemo(Boolean trackResurrection) { Display(0, String.Format( "\n\nDemo start: WeakReferences that {0}track resurrections.", trackResurrection ? "" : "do not "), +1); // Create an object BaseObj obj = new BaseObj("WeakRef"); // Create a WeakReference object that refers to the new object WeakReference wr = new WeakReference(obj, trackResurrection); // The object is still reachable, so it is not finalized. Collect(); WaitForFinalizers(); // The Finalize method should NOT execute obj.Display("Still exists"); // Let's remove the strong reference to the object obj = null; // Destroy strong reference to this object // The following line creates a strong reference to the object obj = (BaseObj)wr.Target; Display("Strong reference to object obtained: " + (obj != null)); obj = null; // Destroy strong reference to this object again. // The GC considers the object to be unreachable and collects it. Collect(); WaitForFinalizers(); // Finalize should run. // This object resurrects itself when its Finalize method is called. // If wr is NOT tracking resurrection, wr thinks the object is dead // If wr is tracking resurrection, wr thinks the object is still alive // NOTE: If the object referred to by wr doesn't have a Finalize method, // then wr would think that the object is dead regardless of whether // wr is tracking resurrection or not. For example: // Object obj = new Object(); // Object doesn't have a Finalize method // WeakReference wr = new WeakReference(obj, true); // obj = null; // Collect(); // WaitForFinalizers(); // Does nothing // obj = (Object) wr.Target; // returns null // The following line attempts to create a strong reference to the object obj = (BaseObj)wr.Target; Display("Strong reference to object obtained: " + (obj != null)); if (obj != null) { // The strong reference was obtained so this wr must be // tracking resurrection. At this point we have a strong // reference to an object that has been finalized but its memory // has not yet been reclaimed by the collector. obj.Display("See, I'm still alive"); obj = null; // Destroy the strong reference to the object // Collect reclaims the object's memory since this object // has no Finalize method registered for it anymore. Collect(); WaitForFinalizers(); // We should see nothing here obj = (BaseObj)wr.Target; // This now returns null Display("Strong reference to object obtained: " + (obj != null)); } // Cleanup everything about this demo so there is no affect on the next demo obj = null; // Destroy strong reference (if it exists) wr = null; // Destroy the WeakReference object (optional) Collect(); WaitForFinalizers(); // NOTE: You are dicouraged from using the WeakReference.IsAlive property // because the object may be killed immediately after IsAlive returns // making the return value incorrect. If the Target property returns // a non-null value, then the object is alive and will stay alive // since you have a reference to it. If Target returns null, then the // object is dead. Display(-1, String.Format("Demo stop: WeakReferences that {0}track resurrections.", trackResurrection ? "" : "do not "), 0); }
private void PushAwayFrom(BaseObj other) { if (other.Mask.Center.x > Base.Mask.Center.x && Base.Physics.hspeed > -1) Base.Physics.hspeed -= Base.Physics.friction * 4; else if (other.Mask.Center.x <= Base.Mask.Center.x && Base.Physics.hspeed < 1) Base.Physics.hspeed += Base.Physics.friction * 4; }
// This method demonstrates how weak references (WR) work. A WR allows // the GC to collect objects if the managed heap is low on memory. // WRs are useful to apps that have large amounts of easily-reconstructed // data that they want to keep around to improve performance. But, if the // system is low on memory, the objects can be destroyed and replaced when // the app knows that it needs it again. private static void WeakRefDemo(Boolean trackResurrection) { Display(0, String.Format( "\n\nDemo start: WeakReferences that {0}track resurrections.", trackResurrection ? "" : "do not "), +1); // Create an object BaseObj obj = new BaseObj("WeakRef"); // Create a WeakReference object that refers to the new object WeakReference wr = new WeakReference(obj, trackResurrection); // The object is still reachable, so it is not finalized. Collect(); WaitForFinalizers(); // The Finalize method should NOT execute obj.Display("Still exists"); // Let's remove the strong reference to the object obj = null; // Destroy strong reference to this object // The following line creates a strong reference to the object obj = (BaseObj) wr.Target; Display("Strong reference to object obtained: " + (obj != null)); obj = null; // Destroy strong reference to this object again. // The GC considers the object to be unreachable and collects it. Collect(); WaitForFinalizers(); // Finalize should run. // This object resurrects itself when its Finalize method is called. // If wr is NOT tracking resurrection, wr thinks the object is dead // If wr is tracking resurrection, wr thinks the object is still alive // NOTE: If the object referred to by wr doesn't have a Finalize method, // then wr would think that the object is dead regardless of whether // wr is tracking resurrection or not. For example: // Object obj = new Object(); // Object doesn't have a Finalize method // WeakReference wr = new WeakReference(obj, true); // obj = null; // Collect(); // WaitForFinalizers(); // Does nothing // obj = (Object) wr.Target; // returns null // The following line attempts to create a strong reference to the object obj = (BaseObj) wr.Target; Display("Strong reference to object obtained: " + (obj != null)); if (obj != null) { // The strong reference was obtained so this wr must be // tracking resurrection. At this point we have a strong // reference to an object that has been finalized but its memory // has not yet been reclaimed by the collector. obj.Display("See, I'm still alive"); obj = null; // Destroy the strong reference to the object // Collect reclaims the object's memory since this object // has no Finalize method registered for it anymore. Collect(); WaitForFinalizers(); // We should see nothing here obj = (BaseObj) wr.Target; // This now returns null Display("Strong reference to object obtained: " + (obj != null)); } // Cleanup everything about this demo so there is no affect on the next demo obj = null; // Destroy strong reference (if it exists) wr = null; // Destroy the WeakReference object (optional) Collect(); WaitForFinalizers(); // NOTE: You are dicouraged from using the WeakReference.IsAlive property // because the object may be killed immediately after IsAlive returns // making the return value incorrect. If the Target property returns // a non-null value, then the object is alive and will stay alive // since you have a reference to it. If Target returns null, then the // object is dead. Display(-1, String.Format("Demo stop: WeakReferences that {0}track resurrections.", trackResurrection ? "" : "do not "), 0); }
private bool KickSuccess(BaseObj other) { return ((Base.Sprite.FacingRight && (other.x + 20) > Kat.x) || (Base.Sprite.FacingLeft && (other.x - 20) < Kat.x)); }
/*********************************** * PRIVATE FUNCTIONS **********************************/ private bool PunchSuccess(BaseObj other) { return ((Base.Sprite.FacingRight && other.x > Kat.x) || (Base.Sprite.FacingLeft && other.x < Kat.x)); }
private bool GroundAttackSuccess(BaseObj other) { return (Kat.Is("Punching") && PunchSuccess(other)) || (Kat.Is("Kicking") && KickSuccess(other)); }
private void GetHurt(BaseObj other, float damage, float hspeed) { Kat.State("Hurt", new object[] { other.x > Kat.x ? -hspeed : hspeed }); Game.HUD.LoseHealth(damage); Game.FreezeFor(0.1f); if (other.x > Kat.x) Stitch.CreateHit(new Vector3(Base.Mask.Right + 10, Base.Mask.Center.y, Base.z)); else Stitch.CreateHit(new Vector3(Base.Mask.Left - 10, Base.Mask.Center.y, Base.z)); }
protected override void setupExpectations() { _data = new BaseObj(); _objectSubscriber.Expect(s => s.OnPublished(_data)); _baseObjSubscriber.Expect(s => s.OnPublished(_data)); }
public static int Main(String[] args) { // Environment.ExitCode = 1; Display("To fully understand this sample, you should step through the"); Display("code in the debugger while monitoring the output generated.\n"); Display("NOTE: The demos in this application assume that no garbage"); Display(" collections occur naturally. To ensure this, the sample"); Display(" objects are small in size and few are allocated.\n"); Display("Main thread's hash code: " + Thread.CurrentThread.GetHashCode()); Introduction(); // GC introduction ResurrectionDemo(); // Demos object resurrection DisposeDemo(); // Demos the use of Dispose & Finalize FinalizationQDemo(); // Demos the use of SuppressFinalize & ReRegisterForFinalize GenerationDemo(); // Demos GC generations WeakRefDemo(false); // Demos WeakReferences without resurrection tracking WeakRefDemo(true); // Demos WeakReferences with resurrection tracking // Demos Finalize on Shutdown symantics (this demo is inline) Display(0, "\n\nDemo start: Finalize on shutdown.", +1); // Normally, when an application terminates, the GC does NOT collect and run finalizers. // The line below forces the GC to do complete object cleanup // GC.RequestFinalizeOnShutdown(); // For default behavior, comment out this line // NOTE: Once you request FinalizeOnShutdown, you cannot change your mind. // When Main returns, obj will have its Finalize method called. BaseObj obj = new BaseObj("Shutdown"); // This is the last line of code executed before the application terminates. Display(-1, "Demo stop: Finalize on shutdown (application is now terminating)", 0); return 100; }
public void SetData(BaseObj obj, GameObject[] addPartsOfFrameObj = null) { this.baseObj = obj; this.addPartsOfFrameObj = addPartsOfFrameObj; }