Improve: alloc using make if alloc size > 65536 (#2796)

This commit is contained in:
Kr328
2023-06-18 11:19:35 +08:00
committed by GitHub
parent 295b0da0e5
commit 154cb1d1f0
3 changed files with 28 additions and 14 deletions

View File

@ -7,6 +7,8 @@ import (
"unsafe"
"golang.org/x/sys/windows"
"github.com/Dreamacro/clash/common/pool"
)
var (
@ -41,8 +43,10 @@ func findProcessPath(network string, from netip.AddrPort, to netip.AddrPort) (st
}
func findPidByConnectionEndpoint(family uint32, protocol uint32, from netip.AddrPort, to netip.AddrPort) (uint32, error) {
buf := []byte(nil)
bufSize := uint32(0)
buf := pool.Get(0)
defer pool.Put(buf)
bufSize := uint32(len(buf))
loop:
for {
@ -77,7 +81,8 @@ loop:
break loop
case uintptr(windows.ERROR_INSUFFICIENT_BUFFER):
buf = make([]byte, bufSize)
pool.Put(buf)
buf = pool.Get(int(bufSize))
continue loop
default: