-
-
Save PathogenDavid/71acd3797e665ea63ceabd74e32e1ffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
// See Pro .NET Memory page 328 | |
// Primitive static fields are stored in the CLR's native heap along with the module, but user-defined structs are actually boxed and stored on the GC heap | |
public unsafe static class Program | |
{ | |
public static int X = 100; | |
public static int Y = 101; | |
public static (int, int) Z = (200, 300); | |
public static void Main() | |
{ | |
Console.WriteLine($"Address of X: {(IntPtr)Unsafe.AsPointer(ref X)}"); | |
Console.WriteLine($"Address of Y: {(IntPtr)Unsafe.AsPointer(ref Y)}"); | |
Console.WriteLine($"Address of Z: {(IntPtr)Unsafe.AsPointer(ref Z)}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment