I have two network buffers that are defined as:
buffer1 = bytearray(4096) buffer2 = bytearray(4096)
What is the fastest way to move content from buffer2
to buffer1
without allocating extra memory?
Naive way:
for i in xrange(4096): buffer1[i] = buffer2[i]
Apparently if I do buffer1[:]=buffer2[:]
, python moves the contents, but I'm not 100% sure, because if I do this:
a = bytearray([0,0,0]) b = bytearray([1,1]) a[:]=b[:]
then len(a)=2
. What happens with a missing byte? Can someone explain how this works or how to move data between buffers?
Thanks.
source share