Best way to define 1D array of double in C# and pass it to and from a C dll.

  • Thread starter Thread starter apm
  • Start date Start date
A

apm

What is the best way to pass an array of double from C# to a win32 dll
written in C? The C code both reads and redefines elements of the array.
Execution speed is also of concern.

Is there anything better than:

double [] x = new double[5000];
fixed(double* X = x)
{
// call dll
unmanageddll(X);
}
 
apm

There probably isn't anythinb better than using the unsafe code. If you
don't use the unsafe code, you would have to marshal the values to an
unmanaged block of memory, and then read them back. This is probably the
fastest way you are going to be able to do this.

Hope this helps.
 
Back
Top