Honestly, I didn't test it or take any performance analyze on it. However, in my experience, P/Invoke is way too heavy to take inside a frequent passed pathway. A much better practice is to create a delegate for it outside the loop (or other kinds of high frequency pathway), and call the delegate instead. The code involved this kind of issue is located in file PcapDeviceCaptureLoop.cs, method CaptureThread line 338:
var result = Mono.Unix.Native.Syscall.poll(pollFds, millisecondTimeout);
object o = SyscallType.InvokeMember("poll", BindingFlags.InvokeMethod, Type.DefaultBinder, null, PollParameters); int result = (int)o;
The better way to do it is to create a delegate in the instance constructor, and call it directly. Unfortunately, the type of the first argument remains unknown at compile time. The good thing is that we still have way to improve it. For example: by using dynamic will get a better performance in frequently called routine; or, we can create a method by using System.Runtime.Reflection.Emit. By doing so, we can get a compiled dll which is portable in both Windows and Linux OS, and get a better performance.
Anonymous
Hello.
I'd love to have a better platform independent way of doing this call. You also mention p/invoke overhead. How would doing a dynamic call not require a p/invoke? In either case, I think there are benchmarks in the unit tests that would let you compare the two implementations.
We can discuss via email if you want, chmorgan@gmail.com