优化gateway-减少GC

This commit is contained in:
boyce
2020-11-03 14:53:49 +08:00
parent 060095baea
commit 974fbd3584
12 changed files with 155 additions and 119 deletions

View File

@@ -101,7 +101,7 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
//msgData := make([]byte, msgLen)
msgData := makeByteSlice(int(msgLen))
if _, err := io.ReadFull(conn, msgData); err != nil {
releaseByteSlice(msgData)
ReleaseByteSlice(msgData)
return nil, err
}
@@ -122,7 +122,7 @@ func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error {
} else if msgLen < p.minMsgLen {
return errors.New("message too short")
}
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
msg := makeByteSlice(p.lenMsgLen+int(msgLen))
// write len