Allow passing ReadOnlySpan<byte>
to Marshal.Copy
#9029
Replies: 2 comments
-
API requests go in @dotnet/runtime. |
Beta Was this translation helpful? Give feedback.
0 replies
-
void* ptr = NativeMemory.Alloc(bytes.Length);
bytes.AsSpan().CopyTo(new Span<byte>(ptr, bytes.Length)); IntPtr ptr = Marshal.AllocHGlobal(bytes.Length); // Only uses this when calling certain Windows APIs
bytes.AsSpan().CopyTo(new Span<byte>(ptr.ToPointer(), bytes.Length)); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Not sure whether this repo is the right place to report this, but I recently discovered that
Marshal.Copy
only takesbyte[]
and notReadOnlySpan<byte>
. Any reason the former can't be allowed as well?I know I can just call
ToArray()
on the span to pass it, but the extra copy to a reference type might not always be desirable.Beta Was this translation helpful? Give feedback.
All reactions