title: C#: Assign array to another array: copy or pointer exchange?
body: <p>Sorry for asking this question, I have been Googling a bit but it seems what comes up is references to clone or copy methods, not an actual answer for my question in <code>C#</code>.</p>
  
  <p>I have two arrays of bytes, and they are being accessed by two threads.</p>
  
  <pre><code>private byte[] buffer1 = new byte[size];
  private byte[] buffer2 = new byte[size];
  </code></pre>
  
  <p>My goal is to write in <code>buffer1</code> in <code>Thread1</code>, grab a mutex, switch the pointers around and repeat the process. <code>Thread2</code> would grab a mutex and always read <code>buffer2</code>.</p>
  
  <p>The goal is that <code>Thread2</code> runs fast and is not affected by the copy taking place in <code>Thread1</code>.</p>
  
  <p>I am very unclear what happens when I do the following:</p>
  
  <pre><code>byte[] temp = buffer1;
  buffer1 = buffer2;
  buffer2 = temp;
  </code></pre>
  
  <p>Are the pointers being switched or is the content of <code>buffer2</code> being copied to <code>buffer1</code>? It should be a simple question but I can't seem to find the solution. <code>Thread1</code> is doing a <code>Marshal.Copy()</code>, and I don't want the call to impact <code>Thread2</code>.</p>