-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make PooledByteBufferWriter public #33598
Comments
The libraries team isn't yet exposing "dangerous" types like this that use Think of it as conceptually similar to the below code, where the compiler enforces lifetime management of the spans to prevent the application from encountering strange failures at runtime. public static Span<byte> GetSpanFoo()
{
Span<byte> theSpan = new byte[100];
return theSpan; // ok
}
public static Span<byte> GetSpanBar()
{
Span<byte> theSpan = stackalloc byte[100];
return theSpan; // compiler fails on this line
} See also #25587, where the proposed |
Hi @GrabYourPitchforks |
Moving to System.Memory since it is a general purpose ask related to buffers/IBufferWriter. |
I 100% agree. We were overly cautious with ArrayBufferWriter but we avoid using it internally because we want to be efficient. I think it should be possible to use the ArrayBufferWriter with pooled buffers. |
I feel the need of a PooledByteBuffer too as stated in #40007 |
This isn't the typical pattern used by the .NET team. Here's a better analogy: we don't often make thread safety guarantees with many of our types. For example, if you have two threads operating on a With The reason we generally don't like using constructor overloads for this is that the entity who makes the safety decision (whoever called the new ctor) and the entity who consumes the buffer writer are often in different libraries. We don't like being in a situation where somebody tests against one implementation and believes that things just work, and then they're handed a different implementation and things fall over in unexpected and unpredictable ways. That's why for both this issue and for #25587 we're brainstorming some kind of compiler or runtime support that would enforce correct behavior on the part of the consumers. If we can get that working, then the concerns about passing these types around dissipates quite a bit. |
Maybe it should be called PooledArrayBufferWriter instead of PooledByteBufferWriter? |
Hi
I'm writing my own serializer using Utf8JsonWriter and Utf8JsonReader.
I have performance tested:
The latter outperforms the first two and it would be awesome if it could be made public (it's internal now). I noticed that once ArrayBufferWriter was internal, but was made public, so I'm hoping the same thing could happen here :-)
The text was updated successfully, but these errors were encountered: