-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-ready-for-reviewAPI is ready for review, it is NOT ready for implementationAPI is ready for review, it is NOT ready for implementationarea-System.Runtime
Milestone
Description
Background and motivation
This would help us to use pooled arrays or fixed size stackallocs, which may not have equal length to the array's rank.
Internally GetFlattenedIndex already uses ROS, so the work would purely be a public api addition.
API Proposal
namespace System;
public class Array
{
public object? GetValue(params ReadOnlySpan<int> indices);
public void SetValue(object? value, params ReadOnlySpan<int> indices);
}API Usage
Array values = ...
var indicesArray = ArrayPool<int>.Shared.Rent(dimensions);
var indices = indicesArray.AsSpan(0, dimensions);
indices.Clear();
do
{
var value = values.GetValue(indices);
...
} (/*increment indices*/);
ArrayPool<int>.Shared.Return(indicesArray);Note: rent follows return in the same method here. In Npgsql we do have uses across methods (some are async as well), where stackalloc cannot be used.
Alternative Designs
No response
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-ready-for-reviewAPI is ready for review, it is NOT ready for implementationAPI is ready for review, it is NOT ready for implementationarea-System.Runtime