Is using Ws2_32.dll in unsafe c# faster than using .net sockets?
<p>I'm building a message router and would like it to be as fast as possible.
I want to stay within c# 4.0 and want to use sockets as fast as possible.
I may not need to bring all the data into managed memory.
I am dealing with byte arrays and am bringing the data into managed memory using this method (unless a better option is found): <a href="http://www.codeproject.com/KB/cs/ReadingStructuresEmit.aspx" rel="nofollow">http://www.codeproject.com/KB/cs/ReadingStructuresEmit.aspx</a></p>

<p>Questions:</p>

<p>1) Is there a performance gain by using sockets in unsafe? how much?</p>

<p>2) Is there a pinvoke or data marshaling hit when using an unsafe method like this (with all structs unsafe as well)</p>

<pre><code>public unsafe partial class Native 
</code></pre>

<p>{</p>

<pre><code>    [DllImport("Ws2_32.dll")]
    public static extern int connect(SOCKET s, sockaddr_in* addr, int addrsize);
</code></pre>

<p>}</p>

<p>3) For #2, does it matter if the data processing happens in unsafe and when the unsafe method returns no data is returned (so <em>maybe</em> nothing is marshaled into managed)?</p>
