From 4bdcbcdbebbe667e0f6f72347788459c3287c521 Mon Sep 17 00:00:00 2001 From: xtaci Date: Tue, 28 Mar 2017 14:25:48 +0800 Subject: [PATCH] only allocate extra buffer when extra header is required --- sess.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sess.go b/sess.go index c308dba..8cea0fa 100644 --- a/sess.go +++ b/sess.go @@ -122,7 +122,6 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn sess.l = l sess.block = block sess.recvbuf = make([]byte, mtuLimit) - sess.ext = make([]byte, mtuLimit) // FEC initialization sess.fecDecoder = newFECDecoder(rxFECMulti*(dataShards+parityShards), dataShards, parityShards) @@ -140,6 +139,12 @@ func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn sess.headerSize += fecHeaderSizePlus2 } + // only allocate extended packet buffer + // when the extra header is required + if sess.headerSize > 0 { + sess.ext = make([]byte, mtuLimit) + } + sess.kcp = NewKCP(conv, func(buf []byte, size int) { if size >= IKCP_OVERHEAD { sess.output(buf[:size])