Skip to content
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

Use Span<T> for APIs #285

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

Marioalexsan
Copy link
Member

Supersedes #263.

To recap, what we want to do is:

  • Multitarget .NET Standard 2.0 and .NET Standard 2.1, and install System.Memory on NS2.0 to gain access to Span there
  • Replace T[] with Span in input parameters where possible - this is a trivial change that just allows slicing
  • Replace T[] returns with Span where possible (i.e. when we want to just give a view into memory) - this reduces the number of allocations and solves some anti-patterns like Image.Pixels
  • Prefer ReadOnlySpan over Span where possible

In some cases, the implementation has to be split in NS2.0 and NS2.1 specific sections to be able to use Span-enhanced methods from .NET. One such example is in StreamAdaptor's Read method, where you can read directly into a Span on NS2.1.

Things to consider:

  • Spans must be used carefully with memory that can get invalidated from the C/C++ side, so we have to make sure that such memory will never be freed / moved for places where we just take the pointers and convert them to spans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant