SOS扩展系列---利用SOS计算变量生存期
下面这个程序有一个bug,试试看你能不能抓住它。
Test.cs (编译成 DelegateExample.exe):
usingSystem;usingSystem.Threading;usingSystem.Runtime.InteropServices;classTest
{delegate uintThreadProc (IntPtr arg);private uintm;public Test (uintn)
{
m=n;
}uintReflect (IntPtr arg)
{
Console.WriteLine (m);returnm;
}static voidMain ()
{
Test t= new Test (1);
ThreadProc tp= newThreadProc (t.Reflect);
NewThread (tp);
Thread.Sleep (1000);
}
[DllImport("UsingCallback")]static extern voidNewThread (ThreadProc proc);
}
- 上一篇: 仅通过转储来排除内存泄漏
- 下一篇: 使用Java中的InputStream读取文件数据