[RFC FS-1081 Discussion] - Extend fixed expressions #421
Replies: 4 comments 9 replies
-
The proposal explicitly states that the The motivation seems to be that this is the same as C#. However, that's not precisely so. C# also supports I think we should include that case. It also makes sense, because we already support This brings up another topic: currently, in F#, you can read/write to whatever This is probably going to stay that way, unless there's a way we can let |
Beta Was this translation helpful? Give feedback.
-
I notice there's also an The following three classes implement Supporting |
Beta Was this translation helpful? Give feedback.
-
It's also interesting to note that fields are only sometimes allowed to be pinned. For example, the following is currently permitted: type MyType = { mutable value: int }
module Point =
let pin (thing: MyType) =
use ptr = fixed &thing.value
printfn "%i" (NativePtr.read ptr) and type MyType =
val mutable value: int
new() = { value = 42 }
member this.Pin () =
use ptr = fixed &this.value
printfn "%i" (NativePtr.read ptr)
() but this is not permitted: type MyType() =
let mutable value = 42
member this.Pin () =
use ptr = fixed &value
printfn "%i" (NativePtr.read ptr)
() I wonder if this is intentional? Shouldn't the 3rd example also work? |
Beta Was this translation helpful? Give feedback.
-
Discussion for RFC FS-1081
Suggestion here: fsharp/fslang-suggestions#761
Beta Was this translation helpful? Give feedback.
All reactions