Add ArrayBufferWriter<T> polyfill - #611
Merged
Merged
Conversation
Recreates System.Buffers.ArrayBufferWriter<T> for the targets where the BCL does not have it (net461-net481, netstandard2.0, netcoreapp2.0-2.2, uap10.0), gated on FeatureMemory since it needs IBufferWriter<T>, Memory<T> and Span<T>. Everything from netcoreapp3.0/netstandard2.1 up gets a TypeForwardedTo. The implementation was taken from the net11 System.Memory assembly, so the growth formula, the Array.MaxLength clamp and the exception types and messages match the shipping type. ResetWrittenCount only arrived in net8.0, so netcoreapp3.x, netstandard2.1 and net5.0-net7.0 have the type but not that member. As with CollectionsMarshal, that window is covered by a separate extension method file. It delegates to Clear(), which zeroes the reclaimed space and is O(n) rather than O(1), noted in the api list. Neither System.Memory nor Microsoft.Bcl.Memory ship the type, so no RefsBclMemory guard is needed. Closes #610
This was referenced Sep 19, 2026
This was referenced Sep 21, 2026
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recreates System.Buffers.ArrayBufferWriter for the targets where the BCL does not have it (net461-net481, netstandard2.0, netcoreapp2.0-2.2, uap10.0), gated on FeatureMemory since it needs IBufferWriter, Memory and Span. Everything from netcoreapp3.0/netstandard2.1 up gets a TypeForwardedTo.
The implementation was taken from the net11 System.Memory assembly, so the growth formula, the Array.MaxLength clamp and the exception types and messages match the shipping type.
ResetWrittenCount only arrived in net8.0, so netcoreapp3.x, netstandard2.1 and net5.0-net7.0 have the type but not that member. As with CollectionsMarshal, that window is covered by a separate extension method file. It delegates to Clear(), which zeroes the reclaimed space and is O(n) rather than O(1), noted in the api list.
Neither System.Memory nor Microsoft.Bcl.Memory ship the type, so no RefsBclMemory guard is needed.
Closes #610