Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Whats the most efficient way to copy data from one large byte array to another?
Posted

It's System.Array.CopyTo, see also System.Array.Clone for exact clone.

—SA
 
Share this answer
 
Comments
Ed Nutting 18-May-11 14:52pm    
Short and sweet, my 5 :)
Sergey Alexandrovich Kryukov 18-May-11 15:03pm    
Thank you very much. It's using it can appear long and bitter. :-) Why copying them, I would wonder? Very often better design allows to avoid it.
--SA
Ed Nutting 18-May-11 15:06pm    
Yes true but then I have come across an occasion, just one admittedly, when I could see no way round the problem other than cloning the array I was lumbered with, though it was only a small array so it didn't matter much. But yes, in general best not to copy/duplicate ;P
Sergey Alexandrovich Kryukov 18-May-11 16:09pm    
We agree... :-)
--SA
In addition to SA's solution, there is always Buffer.BlockCopy[^] - not sure if it's any more efficient but this SO thread[^] indicates it may be.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-May-11 17:28pm    
Good to know, my 5. Something tells me BlockCopy and Array.CopyTo share the same implementation.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900