-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: Add span based apis for Array.CreateInstance/GetValue/SetValue #81826
Comments
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsBackground and motivationAvoid extra memory allocate during reflections/serialization API ProposalArray.CreateInstance(Type, int[])
Array.CreateInstance(Type, int[], int[])
Array.GetValue(int[])
Array.SetValue(object, int[])
+ Array.CreateInstance(Type, Span<int>)
+ Array.CreateInstance(Type, Span<int>, Span<int>)
+ Array.GetValue(Span<int>)
+ Array.SetValue(object, Span<int>)
... API Usagevar lengths = (stackalloc int[] { 1, 2 });
var lowerBounds = (stackalloc int[] { 3, 4 });
var array = Array.CreateInstance(typeof(int), lengths, lowerBounds);
// we can use 'MemoryMarshal.GetArrayDataReference' instead of 'GetValue/SetValue'
// but 'CreateInstance' still have to allocate extra memories
var reference = Unsafe.As<byte, int>(ref MemoryMarshal.GetArrayDataReference(array)); Alternative DesignsNo response RisksNo response
|
CC. @jkotas, @BruceForstall This seems like general goodness and helps make certain type of multi-dimensional array handling "better". However, I imagine if it is, we may want |
It makes it better, but it is not going to be by much. These APIs are still going to be slow APIs that do a lot of work even after this change.
Do you mean #76478? There is no |
Yes, that's the one I was thinking of. |
Going to close this based on the feedback above. We already have overloads that avoid allocating for the common cases of 1/2/3 lengths. For more lengths we may end up adding |
Background and motivation
Avoid extra memory allocate during reflections/serialization
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: