微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/csharp/91424.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐