Closed ronaldvdv closed 4 years ago
My simple thought would be
SendFrame()
without any allocations.Msg
to use a class similar to the static BufferPool
class for sharing AtomicCounter
instances?Sounds good to me, we can add that to the interface, or add a new interface which also allows creating the AtomicCounter. The default implementation can be to just use the GC.
Cool! Not sure which option is best...
IBufferPool
Do you have a strong preference? And should I give it a try and create a pull request?
Let's try to change the existing interface together with c# 8.0 default implementation for the new methods, which will just allocate from the GC.
I've forked and created a branch, but I noticed since NetMQ also targets .NET Standard 2.0, we cannot use default interface implementations (see https://github.com/dotnet/docs/issues/13656). So for now I'll go with the option of adding another interface (so we don't break existing code either), but I'm happy to change that if you feel otherwise.
Due to the new release can this issue be closed?
Environment
Expected behaviour
I've implemented a small
IBufferPool
implementation that uses anArrayPool<byte>
for sharing byte buffers betweenMsg
instances. My goal is to be able to send frames without allocation where possible.Actual behaviour
When profiling I realized the
Msg.InitPool()
call is still allocating, because it instantiates anAtomicCounter
.Steps to reproduce the behaviour
Add the following class:
Then initialize it as follows.
var bufferPool = new ArrayPoolBufferPool(); BufferPool.SetCustomBufferPool(bufferPool);
Finally, create a socket, use socket.SendFrame(...data...) and run a profiler to measure allocations. It will show that
Msg.InitPool()
still allocates 20 bytes for theAtomicCounter
.