110,534
社区成员
发帖
与我相关
我的任务
分享
object obj = new object();
GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
IntPtr addr = handle.AddrOfPinnedObject();
//做一些事情。
//记住,不能像4楼那样释放了handle 返回一个地址,
//因为一旦handle 释放,地址将不再固定,很可能会改变。
//
handle.Free();
int number;
unsafe
{
// Assign the address of number to a pointer:
int* p = &number;
// Commenting the following statement will remove the
// initialization of number.
*p = 0xffff;
// Print the value of *p:
System.Console.WriteLine("Value at the location pointed to by p: {0:X}", *p);
// Print the address stored in p:
System.Console.WriteLine("The address stored in p: {0}", (int)p);
}
// Print the value of the variable number:
System.Console.WriteLine("Value of the variable number: {0:X}", number);
System.Console.ReadKey();
用这个又没什么不好的