Example #1
0
        public static void TestMyHardClass()
        {
            var mlc1 = new MyLittleClass(0xAAAAAAAA);
            var mlc2 = new MyLittleClass(2222);
            var mlc3 = new MyLittleClass(3333);
            var mlc4 = new MyLittleClass(4444);

            hard.Add(mlc1);
            hard.Add(mlc2);
            hard.Add(mlc3);
            hard.Add(mlc4);

            #region [ReferenceEquals]
            //Does it point to the same heap location?
            //if (!object.ReferenceEquals(mlc1, hard.hardReferences[0]))
            //    Console.WriteLine("References are different mlc1, hard.hardReferences[0]");
            //else
            //    Console.WriteLine("References are identical mlc1, hard.hardReferences[0]");
            #endregion

            #region [UNSAFE Get memory Locations]
            //unsafe
            //{
            //    TypedReference tr = __makeref(mlc1);
            //    IntPtr ptr1 = **(IntPtr**)(&tr);

            //    MyLittleClass reff = hard.hardReferences[0];
            //    tr = __makeref(reff);
            //    IntPtr ptr2 = **(IntPtr**)(&tr);

            //    Console.WriteLine(ptr1.ToString("X"));
            //    Console.WriteLine(ptr2.ToString("X"));
            //}
            #endregion
        }
Example #2
0
        public static void TestMyWeakClass()
        {
            var mlc1 = new MyLittleClass(1111);
            var mlc2 = new MyLittleClass(2222);
            var mlc3 = new MyLittleClass(3333);
            var mlc4 = new MyLittleClass(4444);

            weak.Add(mlc1);
            weak.Add(mlc2);
            weak.Add(mlc3);
            weak.Add(mlc4);

            //mlc1 = null;
            //mlc2 = null;
            //mlc3 = null;
            //mlc4 = null;
        }
Example #3
0
 public void Add(MyLittleClass mlc)
 {
     weakReferences.Add(new WeakReference <MyLittleClass>(mlc));
 }
Example #4
0
 public void Remove(MyLittleClass mlc)
 {
     hardReferences.Remove(mlc);
 }
Example #5
0
 public void Add(MyLittleClass mlc)
 {
     hardReferences.Add(mlc);
 }