Array.Copy如何在C#中实现? [英] How is Array.Copy implemented in C#?

查看:554
本文介绍了Array.Copy如何在C#中实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用ILSpy来查看C#中Array.Copy的实现,但是并没有向我展示实现本身.

I tried to look at the implementation of Array.Copy in C# with ILSpy but it didn't show me the implementation itself.

我写了一个简单的基准Array.Copy与一个简单的for循环来复制数据. Array.Copy更快.

I wrote a simple benchmark, Array.Copy vs a simple for loop to copy the data. Array.Copy was faster.

如何更快地实施?

谢谢, 谢伊

推荐答案

用于编写快速memcpy函数的相同技术:

Same techniques used to write a fast memcpy function:

  • 循环展开
  • 大块对齐数据的传输(通常使用SIMD)
  • CPU缓存提示(SIMD在这里也有帮助)

另请参阅:

  • Very fast memcpy for image processing?
  • How to increase performance of memcpy
  • does rewriting memcpy/memcmp/... with SIMD instructions make sense

这篇关于Array.Copy如何在C#中实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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