You don't need to use bufio, but you'll need buffering to decrement the
count of Read calls (thus, syscalls).
Reusing []byte slices: use a sync.Pool. Or several sync.Pools for different
byte slices.

Vasiliy Tolstov <v.tols...@selfip.ru> ezt írta (időpont: 2017. dec. 19., K,
11:30):

> If I have something like this, but I know that client sends fixed sized
> message header 48 byte and variable sized body based on data in header, and
> want to minimize allocations. Does I need to use bufio?
> Now I'm use goleveldb util package for reusable byte slice.
>
> 19 Дек 2017 г. 11:22 пользователь "Dan Kortschak" <
> dan.kortsc...@adelaide.edu.au> написал:
>
>> bufio.NewReader
>>
>> On Mon, 2017-12-18 at 05:11 -0800, Tamás Gulácsi wrote:
>> > >         n, err := sock.Read(buf)
>> > >
>> > >
>> > This will be slow: TCP is a streaming protocol, so this Read can read
>> > any
>> > length between 0 (! yes !) and 1024 bytes.
>> > Use buffering (bytes.NewReader) and some kind of message separation
>> > (e.g.
>> > bufio.Scanner for a line-oriented protocol).
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to