PInvoke or using /clr:pure to compile
- by Yin Zhu
I have a set of numerical libraries in C++ and I want to call them interactively in a interpretive language like F# or IronPython.
So I have two choices now:
Compile the library in native DLL and use PInvoke to call functions in it.
Compile the C++ library to .Net dll using visual c++ (/clr:pure compile option).
The advantage of 1 is that it is very fast, however there are more work in it, e.g. I cannot PInvoke double pointer (e.g. float **), I must write another wrapper in the C++ library to make the interface friendly to .Net.
The advantage of 2 is that I don't need to do know Mashaling strings, arrays, etc. However, the .net dll is slower compared to the native one.
What others factors should be considered when choosing between the two?