难道F#具有相当的语法C#的"不安全"块 [英] Does F# have equivalent syntax to C#'s "unsafe" block

查看:180
本文介绍了难道F#具有相当的语法C#的"不安全"块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多数组边界检查的减慢速度,这是特别真实的二维数组。有没有一种方法来在F#中写的不安全code块?

A lot of array boundary checking slows down the speed, this is especially true to 2D arrays. Is there a way to write unsafe code blocks in F#?

推荐答案

我不是一个的 F#程序员,但据我可以看到它似乎不具备的不安全关键字。

I'm not a F# programmer but as far as I can see it doesn't seem to have the unsafe keyword.

你可能得到的性能提升了二维数组转化为一个一维数组。

You could possibly get a performance boost by transforming the 2D array to an one-dimensional array.

建议5:直到我们得到这个权利,我   将表明.NET用户做什么   许多C ++程序员的数值做:   写一个类来实现你的   n维阵列。这将是   重新presented作为1维阵列   和有关的访问会   通过转换n个索引为1   适当的乘法。我们   几乎可以肯定不会消除   边界检查到一维数组,   但至少我们会只做一查!

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!

<一个href="http://blogs.msdn.com/b/clr$c$cgeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx">Array边界检查消除在CLR

这篇关于难道F#具有相当的语法C#的&QUOT;不安全&QUOT;块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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