Runtime: What happened to the Sequence Helper methods in System.Buffers.Experimental?

Created on 7 Apr 2019  路  4Comments  路  Source: dotnet/runtime

I know System.Buffers.Experimental package has been removed some time ago, but I couldn't find any hints where the helper methods within were moved, specifically the public static ReadOnlySpan<Byte> ToSpan(this ReadOnlySequence<Byte> sequence) methods which were pretty convenient way to turn the sequence into a ReadOnlySpan<byte> to pass it to methods accepting it, i.e. Socket.SendAsync extension method.

Are these just moved or removed for good? And if so why?

I find it rather difficult to write stuff from pipes to other classes which accept only ReadOnlySpan<T>/ReadOnlyMemory<T> (in particular the Socket Task extensions methods without additional allocations, i.e. pipes give me a ReadOnlySquence<byte> whereas Sockets.Send only accepts ReadOnlySpan<byte> and is blocking, where Sockets.SendAsync requires ReadOnlyMemory<bytes>.

The sync Send method is blocking and running separate thread isn't an option (there maybe 100s connections at the same time), but SendAsync requires ReadOnlyMemory<byte> which I find no easy way to get there w/o allocations.

area-System.Memory question

Most helpful comment

I find it rather difficult to write stuff from pipes to other classes which accept only ReadOnlySpan/ReadOnlyMemory (in particular the Socket Task extensions methods without additional allocations, i.e. pipes give me a ReadOnlySquence whereas Sockets.Send only accepts ReadOnlySpan and is blocking, where Sockets.SendAsync requires ReadOnlyMemory.

If you're using the Socket task extension methods then you can just do a loop over the ReadOnlySquence and call SendAsync multiple times.

All 4 comments

I find it rather difficult to write stuff from pipes to other classes which accept only ReadOnlySpan/ReadOnlyMemory (in particular the Socket Task extensions methods without additional allocations, i.e. pipes give me a ReadOnlySquence whereas Sockets.Send only accepts ReadOnlySpan and is blocking, where Sockets.SendAsync requires ReadOnlyMemory.

If you're using the Socket task extension methods then you can just do a loop over the ReadOnlySquence and call SendAsync multiple times.

If you're using the Socket task extension methods then you can just do a loop over the ReadOnlySquence and call SendAsync multiple times.

Ah thanks. Right, that happens when you depend/trust into intellisense auto-completition ;)

And to your initial question about where the methods exist now, the related extension methods you were looking for are here:
https://github.com/dotnet/corefx/blob/02d4a83f640a802ae34588579ba25e8d77ead8ac/src/System.Memory/ref/System.Memory.cs#L123-L129

ReadOnlySequence has the simillar CopyTo and ToArray extension methods that we shipped in 2.1.

The ToSpan/etc. methods you were looking for came from corefxlab (along with the other experimental APIs), which we don't have plans to promote to corefx: https://github.com/dotnet/corefxlab/blob/77178bb06f1187596d16336084e984a14bbe10e1/src/System.Buffers.Experimental/System/Buffers/Sequences/SequenceExtensions.cs#L12-L21

@ahsonkhan Thanks.

Was experimenting with the new System.Memory/System.IO.Pipelines in the past on some toy project and recently was trying to get rid of that old dependency.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitAntoinee picture GitAntoinee  路  3Comments

chunseoklee picture chunseoklee  路  3Comments

aggieben picture aggieben  路  3Comments

btecu picture btecu  路  3Comments

yahorsi picture yahorsi  路  3Comments