(ReadOnly)SpanView<T> and (ReadOnly)MemoryView<T> #24
Labels
feature request 📬
A request for new changes to improve functionality
high-performance 🚂
Issues/PRs for the HighPerformance package
Describe the problem this feature would solve
Currently you cannot conveniently manipulate strided memory via
Memory<T>
andSpan<T>
, as they have no support for stride. While it may soon be possible to manually create instances of (ReadOnly
)RefEnumerable<T>
(via CommunityToolkit/WindowsCommunityToolkit#3645), they cannot always be used for this purpose as they operate in terms ofT
and notbyte
.Describe the solution
These four new types (
SpanView<T>
,ReadOnlySpanView<T>
,MemoryView<T>
andReadOnlyMemoryView<T>
) provide a solution to this problem by providing a strided "view" over an existing (ReadOnly
)Span<T>
or (ReadOnly
)Memory<T>
's data. This allows safe and convenient access to strided data, such as interleaved mesh data buffers:Using the proposed API, the following code can be written:
A sample implementation of these types can be found here. Note that there are several optimizations and improvements that can be made (especially as this was written for .NET Standard 2.0). These are only intended to serve as a reference.
Unanswered questions
unmanaged
constraint be removed from the API? Currently it is necessitated by the use of (ReadOnly
)Span<byte>
.MemoryViewMarshal
?Describe alternatives you've considered
Previously I proposed CommunityToolkit/WindowsCommunityToolkit#3641 to allow manual creation of (
ReadOnly
)RefEnumerable<T>
, but it was found to be unsuitable for many of the scenarios these types are intended to solve.The text was updated successfully, but these errors were encountered: