大量的数组边界检查会降低速度,尤其是二维数组。有没有办法在 F# 中编写不安全的代码块?
最佳答案
我不是 F#程序员,但据我所知,它似乎没有 unsafe关键字。
通过将二维数组转换为一维数组,您可能会获得性能提升。
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!
关于c# - F# 是否具有与 C#'s "unsafe"block 等效的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3650067/