Skip to content

Add ArrayBufferWriter<T> polyfill - #611

Merged
SimonCropp merged 1 commit into
mainfrom
Add-ArrayBufferWriter-T-polyfill
Sep 18, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
Add-ArrayBufferWriter-T-polyfill

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

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

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
@SimonCropp
SimonCropp merged commit d384f95 into main Sep 18, 2026
3 of 5 checks passed
@SimonCropp
SimonCropp deleted the Add-ArrayBufferWriter-T-polyfill branch September 18, 2026 23:27
@SimonCropp SimonCropp added this to the 11.4.0 milestone Sep 18, 2026
This was referenced Sep 19, 2026
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.

Consider adding polyfills for ArrayBufferWriter<T> Class

1 participant