Add public API MemoryMarshal.GetArrayDataReference#1036
Merged
GrabYourPitchforks merged 7 commits intodotnet:masterfrom Jan 8, 2020
Merged
Add public API MemoryMarshal.GetArrayDataReference#1036GrabYourPitchforks merged 7 commits intodotnet:masterfrom
GrabYourPitchforks merged 7 commits intodotnet:masterfrom
Conversation
src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Dec 18, 2019
src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Dec 19, 2019
jkotas
reviewed
Dec 19, 2019
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Dec 19, 2019
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.cs
Outdated
Show resolved
Hide resolved
jkotas
approved these changes
Jan 6, 2020
Member
jkotas
left a comment
There was a problem hiding this comment.
LGTM (modulo the decision on the name).
ahsonkhan
reviewed
Jan 7, 2020
...reclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/MemoryMarshal.CoreCLR.cs
Outdated
Show resolved
Hide resolved
ahsonkhan
reviewed
Jan 7, 2020
ahsonkhan
reviewed
Jan 7, 2020
ahsonkhan
approved these changes
Jan 7, 2020
Member
Author
|
Derp - I forgot the libraries part of the change. |
Member
Author
|
Test failures were caused by #1386, which is now fixed. Merging this PR. |
Member
|
There's another reference to the deleted API in crossgen2 here: I'm on my phone now, done for the day (and still on parental leave anyway). In case someone hits this before it's fixed, cc @dotnet/crossgen-contrib |
Member
Author
|
@MichalStrehovsky Thanks for the heads up - will get a new PR out for those. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves https://github.com/dotnet/corefx/issues/36133.
This introduces a new public API
public static MemoryMarshal.GetRawArrayData<T>(T[] array) : ref T. It's similar in spirit to the existingMemoryMarshal.GetReference, with the following explicit behaviors:Unsafe.IsAddressGreaterThan) in all cases, but it can only be safely dereferenced in the case where the input array is not zero-length.MemoryMarshal.GetReference, which will return nullptr (as a T&) when given aSpan<T>generated from a nullT[].string[]to this API and to get a ref object back. Such a thing can be safely dereferenced (subject to the zero-length argument caveat mentioned above), but it must never be written to unless the caller knows that the value being written is compatible with the actual type of the array.For an example of that last bullet point above:
In API review, we had decided on naming this method
MemoryMarshal.GetReferenceto match the existing span-based overloads. However, after some experimentation I realized that the logic we based our decision on was faulty - see my comment at https://github.com/dotnet/corefx/issues/36133#issuecomment-566834006 for more info. So for this PR I've reverted back to the originally suggested name. If we want to keep theGetReferencename anyway I can do that - just let me know and I can update this PR.