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

Comment and buffer size don't match #167

Closed
bronson opened this issue Apr 16, 2021 · 3 comments
Closed

Comment and buffer size don't match #167

bronson opened this issue Apr 16, 2021 · 3 comments

Comments

@bronson
Copy link

bronson commented Apr 16, 2021

The comment says it's using a 64 KiB buffer but the code allocates a 256 KiB buffer.

image

Maybe the code should be [u8; 65536] or ['\0'; 65536]?

Or leave it. It works fine as is!

Link to the code:

let mut buffer = [0; 65536];

@oconnor663
Copy link
Member

Are you sure it's allocating 256 KiB? My reading of that code is that it's doing what it says. (Specifically, that the type of the array elements are inferred to be u8 based on the call to read().)

@bronson
Copy link
Author

bronson commented Apr 17, 2021

I'm wrong! Yesterday I instrumented your code (what I should have done first) and saw it actually IS 64KiB.

I filed the issue after writing a test program that shows it's 256KiB... But I didn't realize Rust backpropagates type inference. It's 256KiB, until you pass it to a function that accepts byte arrays, whereupon Rust snaps it to the right size.

Sorry for the noise, closing...

@bronson bronson closed this as completed Apr 17, 2021
@oconnor663
Copy link
Member

Yeah the rule is that integer literals default to i32 unless some other constraint is deduced. In production code, there's almost always some constraint, but in hello-world examples not always.

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

2 participants