prealloc them buffers

This commit is contained in:
Jay Wren
2025-11-11 15:20:50 -05:00
parent b2bc6a09ca
commit 226787ea1f
4 changed files with 121 additions and 84 deletions

View File

@@ -55,41 +55,3 @@ func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
return msgs, buffers, names
}
func (u *StdConn) PrepareWriteMessages4(n int) ([]rawMessage, []iovec, [][]byte) {
msgs := make([]rawMessage, n)
iovecs := make([]iovec, n)
names := make([][]byte, n)
for i := range msgs {
names[i] = make([]byte, unix.SizeofSockaddrInet4)
// Point to the iovec in the slice
msgs[i].Hdr.Iov = &iovecs[i]
msgs[i].Hdr.Iovlen = 1
msgs[i].Hdr.Name = &names[i][0]
msgs[i].Hdr.Namelen = unix.SizeofSockaddrInet4
}
return msgs, iovecs, names
}
func (u *StdConn) PrepareWriteMessages6(n int) ([]rawMessage, []iovec, [][]byte) {
msgs := make([]rawMessage, n)
iovecs := make([]iovec, n)
names := make([][]byte, n)
for i := range msgs {
names[i] = make([]byte, unix.SizeofSockaddrInet6)
// Point to the iovec in the slice
msgs[i].Hdr.Iov = &iovecs[i]
msgs[i].Hdr.Iovlen = 1
msgs[i].Hdr.Name = &names[i][0]
msgs[i].Hdr.Namelen = unix.SizeofSockaddrInet6
}
return msgs, iovecs, names
}