mhowlett / NNanomsg

.NET binding for nanomsg
MIT License
179 stars 52 forks source link

FYI: Native Interop #20

Closed buybackoff closed 9 years ago

buybackoff commented 9 years ago

A question partially based on your code and an answer from a guru http://stackoverflow.com/questions/27981719/c-sharp-native-interop-why-most-libraries-use-loadlibrary-and-delegates-instea/

kwpatrick commented 9 years ago

We used DllImport at a previous point.

https://github.com/mhowlett/NNanomsg/blob/ccebbfa2945da08f506419f98022027ca26ce385/NNanomsg/Interop.cs

Matt had issues with this style of interop on Linux/Mono/x64, though, which was surprisingly alleviated for him by changing to delegate interop. I believe there's a closed issue which has more details, but IIRC it stems from some marshalling-unfriendly string handling in the native nanomsg library.

I measured a small performance differential in local pubsub concurrency testing when the delegate interop was introduced. The SO article you link to makes it seem a bit more of a disaster than it is in practice.

If it can be done in a way which doesn't reintroduce platform-specific issues we could easily resurrect DllImport interop. Care to help?

buybackoff commented 9 years ago

Thank you for your detailed response! I do not think that in IO-bound work that matters too much and good to know that you tested it and it is not that bad. I was somewhat confused while reading the code, though.