Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Add a safe stackalloc function that returns a Span #720
Add a safe stackalloc function that returns a Span
I propose we add a function that returns a
The existing way of approaching this problem in F# is ...
open FSharp.NativeInterop open System let inline stackalloc<'a when 'a: unmanaged> size = let p = NativePtr.stackalloc<'a> size |> NativePtr.toVoidPtr Span<'a>(p, size)
I propose that the function's signature would be as the above. Furthermore, explicit type arguments should not be required. Even in constructs like
The function above causes the compiler to complain twice about unverifiable code. The proposal should not produce any compiler warnings, just like in C#.
Also, returning a
Pros and Cons
The advantages of making this adjustment to F# are the ability to simply and safely exploit the memory in the stack and feature parity with the C# compiler.
The disadvantages of making this adjustment to F# are (the section is intentionally left blank)
Estimated cost (XS, S, M, L, XL, XXL): M (for the last paragraph of my proposal,
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply: