Buffer.BlockCopy will be my choice.
Microsoft example: http://msdn.microsoft.com/en-us/library/system.buffer.blockcopy.aspx
const int INT_SIZE = 4; int[] arr = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; Buffer.BlockCopy(arr, 3 * INT_SIZE, arr, 0 * INT_SIZE, 4 * INT_SIZE); foreach (int value in arr) Console.Write("{0} ", value);
Your code will look like this:
uncompressedData = GetNextUncompressedBlock(); int compressedLength = compress(buffer, uncompressedData); Buffer.BlockCopy(buffer, 0, buffer, 0, compressedLength);
source share