-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Span<T> in C# on RepeatedField<T> #16745
Comments
I'd want the input of @JamesNK on this (for consistency with other .NET APIs), but I don't think I object to exposing a |
@jskeet The objection on
If exposing If you prefer a |
@PascalSenn: Yes, basically this ends up being problematic any time things are changed. The use of a span makes it less likely that that will cause problems, as it's harder to keep one around long term. (The code using the span would need to call the code that modifies the repeated field.) That's not true with Personally I'm okay with documentation on the span property that says "if the repeated field is modified, you're in undefined territory in terms of the span". |
@jskeet I do not require |
What language does this apply to?
c# protobuf 3
Describe the problem you are trying to solve.
The issue #6217 was recently marked as stale, but the problem it addresses is still relevant. The goal is to work with a
Span<T>
of a RepeatedField<T>
in C# Protobuf, which would allow for working with apis like vectors and reuse of already allocated memory. Accessing the internal array of a RepeatedField would make this possible.I have read through the discussions on the issue and the PR #6538.
Describe the solution you'd like
Ideally, provide access to a
ReadOnlySpan<T>
of the internal array of aRepeatedField<T>
. I understand that modifying the array after creating a span from it could lead to unexpected behavior, but in most cases, incoming messages are not mutated.Describe alternatives you've considered
If providing access to the internal data structures through ReadOnlySpan is not feasible, an alternative solution would be to introduce
CopyTo
methods that accept a Span<T>
as the destination. The proposed method signatures are:Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: