Overview
Related to #614. The ArrayPoolBufferWriter<T> lacks the DangerousGetArray() API which MemoryOwner<T> and SpanOwner<T> have. We should add it there too to make it easier and clearer how to get the underlying array from a writer.
API breakdown
namespace CommunityToolkit.HighPerformance.Buffers;
public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArraySegment<T> DangerousGetArray();
}
Usage example
ArraySegment<byte> segment = bufferWriter.DangerousGetArray();
stream.Write(segment.Array!, segment.Offset, segment.Count);
Breaking change?
No
Alternatives
Use MemoryMarshal.TryGetArray. That's less clear and less discoverable, so not ideal.
Overview
Related to #614. The
ArrayPoolBufferWriter<T>lacks theDangerousGetArray()API whichMemoryOwner<T>andSpanOwner<T>have. We should add it there too to make it easier and clearer how to get the underlying array from a writer.API breakdown
Usage example
Breaking change?
No
Alternatives
Use
MemoryMarshal.TryGetArray. That's less clear and less discoverable, so not ideal.