You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
namespace System.IO
{
public class MemoryStream
{
+ public MemoryStream(Memory<byte> memory);+ public MemoryStream(ReadOnlyMemory<byte> memory);+ public MemoryStream(Memory<byte> memory, bool writable);+ public MemoryStream(Memory<byte> memory, bool writable, bool publicVisible);
public bool TryGetBuffer(out ArraySegment<byte> buffer);
// Use a different name to not break `out var`
+ public bool TryGetMemoryBuffer(out Memory<byte> buffer);
}
}
Usage Examples
newMemoryStream(image1.AsMemory())
Alternative Designs
A new class named ReadOnlyMemoryStream? The current MemoryStream is actually "array stream", but takes the name.
Risks
Unlike span, memory is slower than array AFAIK. Delegating array implementation to Memory may cause performance regression. Memory and ReadOnlyMemory may require 2 versions of fields, or some casting hacks.
The text was updated successfully, but these errors were encountered:
Background and Motivation
Saw code in roslyn creating MemoryStream from underlying array of ImmutableArray.
https://github.com/dotnet/roslyn/blob/a6f654bb03596c2c3392bb16f082cc1615fac425/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs#L921-L922
Proposed API
Usage Examples
Alternative Designs
A new class named
ReadOnlyMemoryStream
? The currentMemoryStream
is actually "array stream", but takes the name.Risks
Unlike span, memory is slower than array AFAIK. Delegating array implementation to
Memory
may cause performance regression.Memory
andReadOnlyMemory
may require 2 versions of fields, or some casting hacks.The text was updated successfully, but these errors were encountered: