Dan*_*dor 0 .net c# optimization unsafe
有没有更好的办法?请注意,我没有使用,fixed因为我需要扫描缓冲区数据.
GCHandle pinned1 = GCHandle.Alloc(Pic1, GCHandleType.Pinned);
IntPtr ptr1 = pinned1.AddrOfPinnedObject();
byte* p1 = (byte*)ptr1.ToPointer();
//...
//...
//...
byte a=*p1;
p1++;
//...
//...
pinned1.Free();
Run Code Online (Sandbox Code Playgroud)
是的,有更好的方法:使用fixed.
您可以简单地将指针指定给另一个变量并对其执行指针算术:
fixed (byte* ptr = pic1)
{
byte* p1 = ptr;
//...
byte a = *p1;
p1++;
//...
}
Run Code Online (Sandbox Code Playgroud)