-
Notifications
You must be signed in to change notification settings - Fork 18k
Variadic func changes []byte(s) cap #24972
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
Comments
This is an implementation detail. You're seeing differences in how the compiler chooses to implement things. The language doesn't guarantee the the capacity on a conversion from a string. For now, if the capacity is important for your application, use |
Thanks @bradfitz I just found it and wanted to let you know. It's not that I was using this in my application, I was just experimenting with it because of curiosity. Do you know which part of the implementation changes the |
If the backing array for the slice is allocated on the heap, it gets its capacity by rounding up to the next object size, in this case 8. |
@randall77 That's great, you've explained all in detail! I was looking for its assembly output and I was suspecting of |
For clarity, I think that the spec might say something about this: "Capacity of a slice is implementation specific when it's not specified explicitly by a |
@inancgumus, that's what #24163 is about. |
Ah OK, sorry, I read the whole conversation now. Thank you. |
What version of Go are you using (
go version
)?Go 1.10.1
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
When you call a variadic func with a byte slice, calling
cap
is creating different results.https://play.golang.org/p/ZcrsUNAbPZr
What did you expect to see?
32 32
What did you see instead?
8 32
The text was updated successfully, but these errors were encountered: