-
Notifications
You must be signed in to change notification settings - Fork 351
Closed
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityhigh-performance 🚂Issues/PRs for the HighPerformance packageIssues/PRs for the HighPerformance package
Description
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.
Metadata
Metadata
Assignees
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityhigh-performance 🚂Issues/PRs for the HighPerformance packageIssues/PRs for the HighPerformance package