Disallow garbage collection in F #

In C #, it's easy to bind an object to the place where it is currently stored using the "fixed" keyword. Here is an example from 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;
    }        

}

How can this be done in F #?

+3
source share
1 answer

you can use gchandle with type pinned

+10
source

Source: https://habr.com/ru/post/1790982/


All Articles