防止F#中的垃圾收集器移动对象

Adr*_* H. 3 f# garbage-collection pointers

在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;
    }        

}
Run Code Online (Sandbox Code Playgroud)

如何在F#中完成?

des*_*sco 10

你可以使用类型为Pinned的GCHandle