Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocating new slice for data on every Receive() #16

Open
jonhoo opened this issue Apr 14, 2015 · 0 comments
Open

Avoid allocating new slice for data on every Receive() #16

jonhoo opened this issue Apr 14, 2015 · 0 comments

Comments

@jonhoo
Copy link

jonhoo commented Apr 14, 2015

In MCRequest.Receive, a new buffer is allocated for every receive for the body of the request:

buf := make([]byte, klen+elen+bodyLen)

It would be great if this function could instead accept a buffer as an argument so that buffers could be re-used across requests. The code could use cap(buf) to ensure that the buffer is long enough, and buf = buf[:klen+elen+bodyLen] to limit its length. Only if it buf is too small should it allocate its own (and potentially warn the caller that the buffer was not used).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant