当前位置: 代码迷 >> C# >> 关于c#三拇指针的使用
  详细解决方案

关于c#三拇指针的使用

热度:7956   发布时间:2013-02-25 00:00:00.0
关于c#中指针的使用
我有一个需求需要使用指针,我创建了一个Parameter类来保存这个指针。
        
public unsafe AnimatorParameter(int* value,string name)
{
    _name   = name;
    _pValue = value;
}

public unsafe int GetValue()
{
    return *_pInt;
}

但是我担心垃圾回收会改变原来值的地址从而导致指针失效,请问我的担心对吗?还有如果确实会失效,那么有什么办法可以避免。
unsafe c#

------解决方案--------------------------------------------------------
用关键字fixed:
  fixed (byte* p = buffer)
            {
                if (!ReadFile(handle, p, 8192, &n, 0))
                {
                    return 0;
                }
            }
  相关解决方案