Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to combine multiple TBytes arrays

What is the best way to combine TBytes arrays?

All arrays are of the same size. I want the content of Array2 to be added to the end of Array1, Array3 to the end of Array2, and so forth.

like image 565
Vinamra Bhantagar Avatar asked Sep 22 '11 19:09

Vinamra Bhantagar


1 Answers

To merge two TBytes together, you have to allocate a third TBytes that is the total length of the two individual TBytes, then copy the bytes from both into it. For example:

var
  arr1, arr2, merged: TBytes;
begin
  ...
  SetLength(merged, Length(arr1) + Length(arr2));
  if arr1 <> nil then Move(arr1[0], merged[0], Length(arr1));
  if arr2 <> nil then Move(arr2[0], merged[Length(arr1)], Length(arr2));
end;
like image 147
Remy Lebeau Avatar answered Oct 13 '22 15:10

Remy Lebeau