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#?
+5
A:
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.
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!
Jonas Elfström
2010-09-06 09:01:42
The MSDN article you point at makes for a really interesting reading :-)
Edgar Sánchez
2010-09-06 11:48:43
I thought so too and since it's about the CLR it should be language agnostic.
Jonas Elfström
2010-09-06 14:47:50
+2
A:
I have not used it to know if/how it applies, but do check out the NativePtr module.
Brian
2010-09-06 18:46:32