F#与C#的“不安全”块具有相同的语法

前端之家收集整理的这篇文章主要介绍了F#与C#的“不安全”块具有相同的语法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
许多阵列边界检查会降低速度,这对2D阵列尤其如此.有没有办法在F#中编写不安全的代码块?

解决方法

我不是一个 F#程序员,但据我看来,它似乎没有 unsafe关键字.

您可以通过将2D数组转换为一维数组来获得性能提升.

Advice 5: Until we get this right,I
would suggest that .NET users do what
many C++ numerical programmers do:
write a class to implement your
n-dimensional array. This would be
represented as a 1-dimensional array,
and the relevant accessors would
convert n indices into 1 via
appropriate multiplications. We
almost certainly wouldn’t eliminate
the bounds check into the 1-d array,
but at least we’d only do one check!

Array Bounds Check Elimination in the CLR

猜你在找的C#相关文章