For a network related framework I need a lot of byte[] buffers to read and write data. When creating a new byte array, the CLR will initialize all values with 0. For buffers used with streams, this seems to be unnecessary overhead:
var buffer = new byte[65536];
var read = await stream.ReadAsync(buffer, 0, buffer.Length);
Is there a way to create a byte[] array without initializing all values with 0 in C#? Probably by invoking a malloc style method? I'm sure this question has been answered, but I didn't find any clues to start with.
ArrayPool<byte>, but also lots more, including a better consumption model, and the ability to use non-contiguous buffers; pipelines is the API that underpins the impressive Kestrel performance. You say "network related framework" - in that case, Pipelines.Sockets.Unofficial (nuget) has a Socket<=>Pipe bridge for direct consumption, and a Stream<=>Pipe bridge if you need intermediaries (for example,SslStream)PositionOfandAdvanceof the API seem to be the dream when it comes to tokenizing / parsing requests. I'll have a look at pipelines when implementing HTTP/2.