优化网络内存池

This commit is contained in:
boyce
2020-12-23 17:15:58 +08:00
parent a34546ff68
commit 73be7dcedf
2 changed files with 3 additions and 13 deletions

View File

@@ -5,8 +5,7 @@ import (
)
type INetMempool interface {
MakeReadByteSlice(size int) []byte
MakeWriteByteSlice(size int) []byte
MakeByteSlice(size int) []byte
ReleaseByteSlice(byteBuff []byte) bool
}
@@ -81,14 +80,6 @@ func (areaPool *memAreaPool) MakeByteSlice(size int) []byte{
return nil
}
func (areaPool *memAreaPool) MakeReadByteSlice(size int) []byte{
return areaPool.MakeByteSlice(size)
}
func (areaPool *memAreaPool) MakeWriteByteSlice(size int) []byte{
return areaPool.MakeByteSlice(size)
}
func (areaPool *memAreaPool) ReleaseByteSlice(byteBuff []byte) bool {
for i:=0;i<len(memAreaPoolList);i++{
if cap(byteBuff) <= memAreaPoolList[i].maxAreaValue {

View File

@@ -100,8 +100,7 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
}
// data
//msgData := make([]byte, msgLen)
msgData := p.MakeReadByteSlice(int(msgLen))
msgData := p.MakeByteSlice(int(msgLen))
if _, err := io.ReadFull(conn, msgData[:msgLen]); err != nil {
p.ReleaseByteSlice(msgData)
return nil, err
@@ -126,7 +125,7 @@ func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error {
}
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
msg := p.MakeWriteByteSlice(p.lenMsgLen+int(msgLen))
msg := p.MakeByteSlice(p.lenMsgLen+int(msgLen))
// write len
switch p.lenMsgLen {
case 1: