-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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]: System.Buffers : BuffersExtensions.AsStream #100434
Comments
Tagging subscribers to this area: @dotnet/area-system-buffers |
For I discarded having |
Re corelib: that's why I proposed the existing BuffersExtensions as the root (or something in the same package/namespace) - it should have all the right refs. |
Noting that we now have When I use |
Considering that static extensions is in the backlog dotnet/csharplang#192, I think we should consider this for 9 while keeping #82801 as future. |
Background and motivation
This is tangentially related to #100290 and the .NET 9 distributed caching epic; the proposed hybid-cache API will use
ReadOnlySequence<byte>
andIBufferWriter<byte>
as the primary serializer APIs, but: not all serializers support these APIs (many do, note) - withStream
being the most common fallback.API Proposal
API Usage
and
The implementations would be
internal
, but:ReadOnlySequenceStream
has aCanRead: true
,CanWrite: false
implementation that supports seek etc; no additional buffer copies, just a few "where are we" counters, usingSequencePosition
iteration and aReadOnlyMemory<byte>
snapshot of the current segmentBufferWriterStream
has aCanRead: false
,CanWrite: true
implementation that does not support seek; position and length are read-only and report the bytes written so far; no double-buffering - it is assumed (as a fundamental part ofIBufferWriter<byte>
) that the underlyingIBufferWriter<byte>
already does some internal work there when responding toGetSpan
/GetMemory
(such that they are affordable), so this would be duplicated effort and an additional mem-copyAlternative Designs
The alternative is to use
MemoryStream
, which involves multiple additional copy operations and additionalbyte[]
buffers.Risks
None seen
Additional
I am happy to contribute the implementation effort.
The text was updated successfully, but these errors were encountered: