The motivation to build and release this package really evolved from two practical issues I encountered when building performance critical C# code:
- Creating a native, high-performance generic array data structure in C# seems to be impossible (see A minimalistic native 64 bit array ...).
- Reading structured binary data from a byte[] requires some ugly hacks to get both decent performance and genericity (see e.g. Reading Unmanaged Data Into Structures).
static unsafe T Read<T>(T* p) { return *p; }But in F#, you can; you'd simply encode this as
open NativeInterop let pVal = NativePtr.read ptrwhere ptr is of type nativeptr<'T> and 'T is constrained to unmanaged types.
The performance offered by the NativeInterop package should be on par with non-generic unsafe C# code. The NativeInterop package also contains an implementation of NativeArray64
No comments:
Post a Comment