On Thu, Mar 12, 2020 at 12:45 AM Nicola Murino <nicola.mur...@gmail.com>
wrote:

>
> what I understand reading that issue is that sync.Pool is not the best
> choice to store variable-length buffers and my first allocator
> implementation accepts buffers of any size, each received packet can
> have different sizes (between 20 and 262144 bytes).
>
>
A trick I learned from the CircleMUD code base (I think!) was that you
often needed a 1024 byte buffer to write to a telnet socket. So you would
keep a list of those handy for fast allocation in the style of sync.Pool.
If you exceeded the buffer, you would allocate a larger buffer to handle
it. If you know a typical packet size, you can cut down the allocation rate
by a factor of how often those packets occur. Chances are that maintaining
a few pools of the correct sizes will work as well as rolling your own.

My initial thought was just as to why it was rejected in the first place.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiWKZ9NhEVVqBemdC3gSxsPT1jTN6q-1A0D2FHBH0wO1ww%40mail.gmail.com.

Reply via email to