优化网络层的GC

This commit is contained in:
boyce
2020-10-29 19:40:44 +08:00
parent 54f1db7641
commit 5e30083ce8
6 changed files with 36 additions and 7 deletions

View File

@@ -99,8 +99,10 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
}
// data
msgData := make([]byte, msgLen)
//msgData := make([]byte, msgLen)
msgData := makeByteSlice(int(msgLen))
if _, err := io.ReadFull(conn, msgData); err != nil {
releaseByteSlice(msgData)
return nil, err
}
@@ -123,8 +125,8 @@ func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error {
}
//msgLen -= 2
msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
msg := makeByteSlice(p.lenMsgLen+int(msgLen))
// write len
switch p.lenMsgLen {
case 1: