Array.Copy VS Buffer.BlockCopy [英] Array.Copy vs Buffer.BlockCopy

查看:608
本文介绍了Array.Copy VS Buffer.BlockCopy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Array.Copy 和的 Buffer.BlockCopy 都做同样的事情,但 BlockCopy 的目的是快速字节-Level基本数组复制,而复制是通用的实现。我的问题是 - 在什么情况下你应该使用 BlockCopy ?如果你在当你复制原始类型的数组,或者你应该只使用它,如果你编码性能的任何时候使用它?有什么内在的危险关于使用 Buffer.BlockCopy Array.Copy

Array.Copy and Buffer.BlockCopy both do the same thing, but BlockCopy is aimed at fast byte-level primitive array copying, whereas Copy is the general-purpose implementation. My question is - under what circumstances should you use BlockCopy? Should you use it at any time when you are copying primitive type arrays, or should you only use it if you're coding for performance? Is there anything inherently dangerous about using Buffer.BlockCopy over Array.Copy?

推荐答案

由于参数Buffer.BlockCopy是字节为基础的,而不是指数型,你很可能搞砸了你的code比,如果你使用Array.Copy,所以我只会用Buffer.BlockCopy在我的code性能关键部分。

Since the parameters to Buffer.BlockCopy are byte-based rather than index-based, you're more likely to screw up your code than if you use Array.Copy, so I would only use Buffer.BlockCopy in a performance-critical section of my code.

这篇关于Array.Copy VS Buffer.BlockCopy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆