111,098
社区成员




Marshal.UnsafeAddrOfPinnedArrayElement
再由IntPtr得到数组用的是: Marshal.Copy
但是引用数组内容时就会报出“尝试读取受保护的内存,这通常指示其它内存已损坏。”后来用ToPointer()由IntPtr得到数组首地址,再结合用unsafe不安全代码去引用数组的内容,不过也是同样的问题。我不知道问题出在哪,该如何解决,还有你说直接用调用windows API怎么用啊?帮忙解决,不胜感激,加分。 unsafe public double* resultGradient = new double[CallDLL.width * CallDLL.height * 3];
这样做是不是不行?因为编译器报错:右边的初始化和左边的double*不匹配。
unsafe class TestClass
{
public int* A;
public TestClass(int[] b)
{
fixed(int* p = b)
{
A = p;
}
}
}
class Program
{
unsafe static void Main(string[] args)
{
int[] x = new int[10];
TestClass tc = new TestClass(x);
*(tc.A + 1) = 255;
Console.ReadLine();
}
}
[StructLayout(LayoutKind.Sequential)]
class TestClass
{
public byte[] a = new byte[1024 * 1024];
}
class Program
{
static void Main(string[] args)
{
TestClass tc = new TestClass();
Console.WriteLine(Marshal.SizeOf(tc));
Console.ReadLine();
}
}