在C#中,很容易使用关键字“fixed”将对象固定到当前存储的位置。以下是MSDN的示例:
unsafe static void TestMethod()
{
// assume class Point { public int x, y; }
// pt is a managed variable, subject to garbage collection.
Point pt = new Point();
// Using fixed allows the address of pt members to be
// taken, and "pins" pt so it isn't relocated.
fixed (int* p = &pt.x)
{
*p = 1;
}
}
如何在F#中完成?