tag:blogger.com,1999:blog-6698224.post-1082153483293025312004-04-16T16:52:00.000-05:002004-08-11T10:01:45.183-05:00Use Buffer.BlockCopy instead of Array.Copy for better performance<span style="font-family:trebuchet ms;font-size:85%;">Buffer.BlockCopy is faster than Array.Copy when you are copying primitive arrays (arrays of type System.Int32, System.Char and so forth).</span> <br /><span style="font-family:Trebuchet MS;font-size:85%;">The reason is because (with base on </span><span style="font-family:trebuchet ms;font-size:85%;">the </span><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=3A1C93FA-7462-47D0-8E56-8DD34C6292F0&displaylang=en"><span style="font-family:trebuchet ms;font-size:85%;">SSCLI implementation</span></a><span style="font-family:trebuchet ms;"><span style="font-size:85%;">) both Buffer.Blockcopy and Array.Copy, call the method m_memmove (declared in comsystem.cpp) that copies data byte per byte from one array to another, <strong>but</strong> the major difference is that Array.Copy performs more validations and operations than Buffer.BlockCopy before calling m_memmove.</span></span> <br /><span style="font-family:trebuchet ms;"><span style="font-size:85%;">Buffer.BlockCopy just checks if bonderies are valid and if the array's data type is primitive, but Array.Copy checks thinks like type compatibility, casting, boxing, unboxing, among other things.</spam></span></span> <br />Danielhttp://www.blogger.com/profile/17636031092965440114noreply@blogger.com