using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// Marshal 域名空间
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string getMemory(object o) // 获取引用类型的内存地址方法
{
GCHandle h = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection);
IntPtr addr = GCHandle.ToIntPtr(h);
return "0x" + addr.ToString("X");
}
private void Form1_Load(object sender, EventArgs e)
{
int num_Size =100000000;
本文探讨了如何在C#中获取并打印对象的内存地址,包括使用 unsafe 代码块和指针来操作,同时讨论了.NET垃圾回收机制对内存地址的影响。
订阅专栏 解锁全文
3837

被折叠的 条评论
为什么被折叠?



