Question

We have some interop code that involves matrices. I was trying to call the native DLL and for the most part it works very reliably.

I am relying on the default marshalling by .net, avoiding unmanaged pointers and rather using .net arrays for the most part, and maybe a byref here and there. The .net article says, that multidimensional arrays are implicitly marshalled as column-major one-dimensional arrays, which would be fine.

The only thing that does not seem to work, is trying to marshal a multi-dimensional array, as the F# compiler complains that float[,] is not allowed in an extern declaration. Is there any way around this limitation?

I am aware of the PinnedArray and PinnedArray2 types from the F# PowerPack, but I was looking for a solution which relies on managed pointers and - more importantly - I'd like to avoid having to include F# PowerPack as a dependency just for the PinnedArray classes.

No correct solution

OTHER TIPS

By this discription about Blittable and Non-Blittable Types in the link below you could try the System.Double in place of float, because they do not require conversion when they are passed between managed and unmanaged code wich means no more special handling by the interop marshaler with a plus in performance: https://msdn.microsoft.com/en-us/library/75dwhxf7%28v=vs.110%29.aspx

I did a search and found this related topic wich may help you:

Threat like a single array: http://stackoverflow.com/a/18607817/4597705
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top