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

Reduce copying with methods to query the inner read buffer #29

Open
parasyte opened this issue Sep 27, 2022 · 0 comments
Open

Reduce copying with methods to query the inner read buffer #29

parasyte opened this issue Sep 27, 2022 · 0 comments

Comments

@parasyte
Copy link

parasyte commented Sep 27, 2022

I am writing a transport to encapsulate SerialPort to add framing and encoding (serde). When I want to read from the port, I need to allocate some space in my Transport but I don't know how many bytes to allocate until the read is actually performed. This means I need to keep an intermediate buffer for bytes to be read into, and then I can copy the number of bytes actually read from the port into my Transport.

However, SerialPort already has internal buffering with a default size of 128 bytes for the read buffer. So, I am effectively triple buffering and copying twice for no good reason.

On the host side with the serialport crate, I can query the number of bytes available in the OS buffer with SerialPort::bytes_to_read(). It is trivial for me to allocate space in my Transport with this API and copy only once.

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