Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnlySpan<byte> friendly overload for WriteFile #612

Closed
jnm2 opened this issue Jul 23, 2021 · 2 comments
Closed

ReadOnlySpan<byte> friendly overload for WriteFile #612

jnm2 opened this issue Jul 23, 2021 · 2 comments
Assignees
Labels
usability Touch-up to improve the user experience for a language projection

Comments

@jnm2
Copy link

jnm2 commented Jul 23, 2021

(0.1.506-beta)

https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile#parameters has void* lpBuffer, uint nNumberOfBytesToWrite. Since the second parameter explicitly defines the previous parameter in terms of bytes, it seems like the friendly overload could replace both parameters with ReadOnlySpan<byte> buffer.

The benefit would be avoiding adding unsafe + fixed around the call.

@AArnott
Copy link
Member

AArnott commented Aug 18, 2021

Hmmmm... unless we special case it (and we try to minimize such cases), the most natural way to achieve this is to get the metadata to change from void* to byte*. If they were to do that, I believe you'd automatically get what you want. And with some other enhancements, the nNumberOfBytesToWrite would also disappear from the friendly overload because that value can come from the span's length.

Although strictly speaking, the current void* allows pointers to any other blittable structure, if that ever was useful to anyone they could do a typecast to make it look like byte* and proceed anyway.

So I'm in favor of this change. Moving to the metadata repo.

@AArnott AArnott transferred this issue from microsoft/CsWin32 Aug 18, 2021
@AArnott
Copy link
Member

AArnott commented Aug 18, 2021

The request for the metadata repo is to change the void* parameter to be byte* instead.

@AArnott AArnott added the usability Touch-up to improve the user experience for a language projection label Aug 18, 2021
@mikebattista mikebattista self-assigned this Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

3 participants