Concat two byte [] returns a System.OutOfMemoryException

I have a problem with concat two bytes []. One of them has more than 300 million bytes. This excludes the type System.OutOfMemoryException.

I am using this code:

byte[] b3 = by2.Concat(by1).ToArray();

can anyone help me

+3
source share
4 answers

- Concat call ToArray , . . , , , .. , . , , (b1.Length + b2.Length) * 2. , LOH GC .

ToArray() -: , .

- :

var b3 = new byte[b1.Length + b2.Length];
Array.Copy(b1, b2, b1.Length);
Array.Copy(b1, 0, b2, b1.Length, b2.Length);

, . , , , ToArray().

+7

, , (, , ).

, , , , , .

+2

, taks , ~ 550 . , .

+1

.. , ~ 600 - . , , , 1 .

You should probably start thinking about other data structures, or try to save them as files and transfer them to edit memory : memmapping of the whole file needs the same contiguous area in the address space, so it solves nothing. This answer will be deleted.

+1
source

All Articles