I am writing C # code that calls the C library, and something is not entirely clear in my mind.
Function C has the following signature:
double* DoSomeStuff(double* input,int numberOfElements);
I displayed the function as:
[System.Runtime.InteropServices.DllImportAttribute("myDll.dll", EntryPoint="DoSomeStuff")] public static extern System.IntPtr DoSomeStuff(ref double input, int numberOfElements) ;
The input value is an array, so the C function expects an adjacent memory layout. I am more familiar with C ++ than with C #. In C ++, I used std :: vector to store data, and then used the data () method to get the pointer and exchange information with C. std :: vector guarantees continuous layout memory.
What data structure can I use in C #? Is there something like std :: vector in C #?
I faced the same problem for a string (in C ++ std :: string there is only std :: vector with some make-up). And I solved the problem using:
System.IntPtr stringExample = Marshal.StringToHGlobalAnsi("StringExample");
A static function does the job for me. Is there something like this function for other types?
I asked too many questions, I think the most important of them: what is the best practice to solve this problem?
thanks
source share