Most efficient way to combine arrays?

  • Thread starter Thread starter chris
  • Start date Start date
C

chris

I have a few byte arrays that I would like to combine into one array
(order needs to be kept). What would be the most efficient way to do
this?
Thanks for your time,
Chris
 
Create an array big enough for both, and then Buffer.BlockCopy the
first array into position 0 and the second array alongside it.

Marc
 
chris said:
I have a few byte arrays that I would like to combine into one array
(order needs to be kept). What would be the most efficient way to do
this?

Not to be smart, but the most efficient way would be not to do it at
all. Either get the producer of the byte arrays to write into a
pre-allocated array (see e.g. the alternative overloads of
Encoding.GetBytes for comparison), or keep the arrays together until you
need to do something else with them such as writing out to file or
network (e.g. see "Socket::Send(IList<ArraySegment<byte>> buffers)").

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top