title: C# Unsafe/Fixed Code
body: <p>Can someone give an example of a good time to actually use "unsafe" and "fixed" in C# code? I've played with it before, but never actually found a good use for it. </p>
  
  <p>Consider this code...</p>
  
  <pre><code>fixed (byte* pSrc = src, pDst = dst) {
      //Code that copies the bytes in a loop
  }
  </code></pre>
  
  <p>compared to simply using...</p>
  
  <pre><code>Array.Copy(source, target, source.Length);
  </code></pre>
  
  <p>The second is the code found in the .NET Framework, the first a part of the code copied from the Microsoft website, <a href="http://msdn.microsoft.com/en-us/library/28k1s2k6(VS.80).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/28k1s2k6(VS.80).aspx</a>.</p>
  
  <p>The built in Array.Copy() is dramatically faster than using Unsafe code. This might just because the second is just better written and the first is just an example, but what kinds of situations would you really even need to use Unsafe/Fixed code for anything? Or is this poor web developer messing with something above his head?</p>