Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 互操作在不封送的情况下传递大型二维数组 我有一个巨大的矩形数组(2GB+),我想传递给C++ DLL。我希望在托管代码中分配内存一次,而不是封送它(太大)。数据是在循环中顺序填充的二维数组。我可以使用以下托管阵列创建它: float[,] masterMatrix = new float[dim1, dim2]; // 2GB + foreach(Sequence seq in sequences) { // get the next matrix & calculate its byte size float[,] result = seq.Process(); int byteSize = (result.GetLength(0) * result.GetLength(1)) * sizeof(float); // append it to the master matrix Buffer.BlockCopy(result, 0, masterMatrix, insertByteIndex, byteSize); insertByteIndex += byteSize; }_C#_C++_Arrays_Interop - Fatal编程技术网

C# 互操作在不封送的情况下传递大型二维数组 我有一个巨大的矩形数组(2GB+),我想传递给C++ DLL。我希望在托管代码中分配内存一次,而不是封送它(太大)。数据是在循环中顺序填充的二维数组。我可以使用以下托管阵列创建它: float[,] masterMatrix = new float[dim1, dim2]; // 2GB + foreach(Sequence seq in sequences) { // get the next matrix & calculate its byte size float[,] result = seq.Process(); int byteSize = (result.GetLength(0) * result.GetLength(1)) * sizeof(float); // append it to the master matrix Buffer.BlockCopy(result, 0, masterMatrix, insertByteIndex, byteSize); insertByteIndex += byteSize; }

C# 互操作在不封送的情况下传递大型二维数组 我有一个巨大的矩形数组(2GB+),我想传递给C++ DLL。我希望在托管代码中分配内存一次,而不是封送它(太大)。数据是在循环中顺序填充的二维数组。我可以使用以下托管阵列创建它: float[,] masterMatrix = new float[dim1, dim2]; // 2GB + foreach(Sequence seq in sequences) { // get the next matrix & calculate its byte size float[,] result = seq.Process(); int byteSize = (result.GetLength(0) * result.GetLength(1)) * sizeof(float); // append it to the master matrix Buffer.BlockCopy(result, 0, masterMatrix, insertByteIndex, byteSize); insertByteIndex += byteSize; },c#,c++,arrays,interop,C#,C++,Arrays,Interop,但是如果我使用IntPtr(这样我就可以直接将它传递到.dll),我如何将结果的数据复制到非托管内存中?Copy只处理一维数组。我知道我可以一个元素一个元素地做,但我希望有更好/更快的方法 IntPtr pointer = Marshal.AllocHGlobal(maxNumBytes); // 2GB + foreach(Sequence seq in sequences) { // get the next matrix & calculate its byte siz

但是如果我使用IntPtr(这样我就可以直接将它传递到.dll),我如何将
结果
的数据复制到非托管内存中?Copy只处理一维数组。我知道我可以一个元素一个元素地做,但我希望有更好/更快的方法

IntPtr pointer = Marshal.AllocHGlobal(maxNumBytes); // 2GB + 
foreach(Sequence seq in sequences)
{
     // get the next matrix & calculate its byte size
     float[,] result = seq.Process();
     int byteSize = (result.GetLength(0) * result.GetLength(1)) * sizeof(float);

     // append it to the master matrix
     Marshal.Copy(/* can't use my result[,] here! */, 0, pointer, byteSize);
     insertByteIndex += byteSize;
}

谢谢你的建议。

有什么建议吗?请勿使用2Gb阵列:D