Array.Copy 是如何在 C# 中实现的? [英] How is Array.Copy implemented in C#?
本文介绍了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 在这里也有帮助)
另见:
这篇关于Array.Copy 是如何在 C# 中实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文