使用Cli包装器将非托管地址传递给C#中的托管函数 [英] Pass unmanaged address to a a managed function in C#with Cli wrapper
问题描述
早上好,
我正在开发一个使用C#代码,C\CLI包装器和C ++代码的项目。实际上,我必须在C ++函数中调用一个托管函数。
我在C ++中的函数有这个原型:
void TestArray( float ** array1, int numRows,< span class =code-keyword> int numCols);
在这个函数中我调用一个C#函数,它有这个原型:
public void TestArray( ref float [,] arrayTest, int numRows, int numCols);
我在C ++函数TestArray中创建了一个包含数组数据的cli :: array array1和我传递给C#函数后。请参阅下面的代码:
cli :: array< float,2> ^ array1_test = gcnew cli: :阵列<浮子,2 - ;(numRows行,数numCols);
...
// 调用C#函数
TestArray(array1_test,numRows,numCols);
但是通过这种方式,我使用了很多副本,我想我想知道是否可以使用数组的地址(由float **传递的参数)并直接传递给C#函数。
提前感谢您的任何建议。
这篇带有代码示例的文章可能会引起您的兴趣:
C#中的非托管数组 - 没问题 [ ^ ]
祝你好运!
Good morning,
I am working on a project which use C# code, a C\CLI wrapper and C++ code. Actually, I have to call an managed function inside a C++ function.
My function in C++ has this prototype :
void TestArray(float** array1, int numRows, int numCols);
Inside this function I call a C# function which has this prototype :
public void TestArray(ref float[,] arrayTest, int numRows, int numCols);
I created in the C++ function TestArray a cli::array which contains the data of the array "array1" and after I passed to the C# function. See below the code :
cli::array<float,2>^ array1_test = gcnew cli::array<float,2>(numRows,numCols);
...
//Call the C#function
TestArray(array1_test, numRows, numCols );
But by using this way, I used lot of copy I guess and I would like to know if it is possible to use the address of the array (the one passed in argument by float**) and passed this one directly to the C# function.
Thank you in advance for any suggestions.
This article with code example may be of interest to you:
Unmanaged Arrays in C# - No Problem[^]
Good luck!
这篇关于使用Cli包装器将非托管地址传递给C#中的托管函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!