title: How to copy a python bytearray buffer?
body: <p>I have two network buffers defined as:</p>
  
  <pre><code>buffer1 = bytearray(4096)
  buffer2 = bytearray(4096)
  </code></pre>
  
  <p>Which is the fastest way to move the content from <code>buffer2</code> to <code>buffer1</code> without allocating extra memory?</p>
  
  <p>The naive way would be to do:</p>
  
  <pre><code>for i in xrange(4096):
      buffer1[i] = buffer2[i]
  </code></pre>
  
  <p>Apparently if I do <code>buffer1[:]=buffer2[:]</code> python moves the content, but I'm not 100% sure of it because if I do:</p>
  
  <pre><code>a = bytearray([0,0,0])
  b = bytearray([1,1])
  a[:]=b[:]
  </code></pre>
  
  <p>then <code>len(a)=2</code>. What happens with the missing byte? Can anyone explain how this works or how to move data between buffers?</p>
  
  <p>Thanks.</p>