public static void testByRef(ref testClass a) { Console.WriteLine(""); Console.WriteLine("Inside test - pass by reference."); GCHandle objHandle = GCHandle.Alloc(a, GCHandleType.WeakTrackResurrection); IntPtr intPtrAddressOfObjectPointer = GCHandle.ToIntPtr(objHandle); IntPtr intPtrObjectPtr = (IntPtr)Marshal.ReadInt32(intPtrAddressOfObjectPointer); Console.WriteLine("E) Address of object pointer: " + intPtrAddressOfObjectPointer + " << This should be same as A?"); //Console.WriteLine("Bytes at address: " + getBytes(intPtrAddressOfObjectPointer)); //Console.WriteLine(""); Console.WriteLine("F) Address of actual object: " + intPtrObjectPtr); }
public static void testByVal(testClass a) { Console.WriteLine(""); Console.WriteLine("Inside test - pass by value."); GCHandle objHandle = GCHandle.Alloc(a, GCHandleType.WeakTrackResurrection); IntPtr intPtrAddressOfObjectPointer = GCHandle.ToIntPtr(objHandle); IntPtr intPtrObjectPtr = (IntPtr)Marshal.ReadInt32(intPtrAddressOfObjectPointer); TypedReference tr = __makeref(a); IntPtr intPtrAlternativeMethod = **(IntPtr**)(&tr); Console.WriteLine("C) Address of object pointer: " + intPtrAddressOfObjectPointer); //Console.WriteLine("Bytes at address: " + getBytes(intPtrAddressOfObjectPointer)); //Console.WriteLine(""); Console.WriteLine("D) Address of actual object: " + intPtrObjectPtr); }
public static void testByVal(testClass a) { Console.WriteLine(""); Console.WriteLine("Inside test - pass by value."); GCHandle objHandle = GCHandle.Alloc(a, GCHandleType.WeakTrackResurrection); IntPtr intPtrAddressOfObjectPointer = GCHandle.ToIntPtr(objHandle); IntPtr intPtrObjectPtr = (IntPtr)Marshal.ReadInt32(intPtrAddressOfObjectPointer); TypedReference tr = __makeref(a); IntPtr intPtrAlternativeMethod = **(IntPtr **)(&tr); Console.WriteLine("C) Address of object pointer: " + intPtrAddressOfObjectPointer); //Console.WriteLine("Bytes at address: " + getBytes(intPtrAddressOfObjectPointer)); //Console.WriteLine(""); Console.WriteLine("D) Address of actual object: " + intPtrObjectPtr); }