Framework code which uses the type nativeptr<unit> isn't usable in F# because we cannot cast any nativeptr to nativeptr<unit>. Exact error is that unit isn't an unmanaged type.
I noticed this after trying to compile simple examples with the Span type from the System.Memory package. Because the C# equivalent of nativeptr<unit> is void* and nothing is wrong with a void pointer I thought reporting this here would be correct.
To have a senseful usage example look at this code (requires the System.Memory package!):
let someOperationWithSpan () =
let data = NativePtr.stackalloc<byte>(256)
let voidPtr = data |> NativePtr.toNativeInt |> NativePtr.ofNativeInt<unit> // This line doesn't compile
let stackMemory = new Span<byte>(voidPtr, 256)
// Do some stuff with the span!
()
Framework code which uses the type
nativeptr<unit>isn't usable in F# because we cannot cast any nativeptr tonativeptr<unit>. Exact error is that unit isn't an unmanaged type.I noticed this after trying to compile simple examples with the Span type from the System.Memory package. Because the C# equivalent of
nativeptr<unit>isvoid*and nothing is wrong with a void pointer I thought reporting this here would be correct.To have a senseful usage example look at this code (requires the System.Memory package!):