特别是,我正在考虑这样的场景:
unsafe struct Foo
{
public int Bar;
public Foo* GetMyAddr()
{
fixed (Foo* addr = &this)
return addr;
}
}
Run Code Online (Sandbox Code Playgroud)
假设存储在非托管内存中的Foo,我试图找出在GetMyAddr中评估fixed语句所涉及的内容.我知道作为程序员,这个结构永远不会在托管堆上,我只需要以最有效的方式在非托管内存中获取它的地址.如果在这里使用任何锁定或原子操作,我会特别担心,因为这会使它完全不合适.