-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
space optimization possible? struct{} takes up space when it is listed last in a struct #17450
Labels
Comments
So strange... if I move the struct{} field to the top, it again no longer takes up space!
|
glycerine
changed the title
space optimization possible? struct{} takes up space when it is not the only member in a struct
space optimization possible? struct{} takes up space when it is listed as 2nd member in a struct
Oct 15, 2016
glycerine
changed the title
space optimization possible? struct{} takes up space when it is listed as 2nd member in a struct
space optimization possible? struct{} takes up space when it is listed last in a struct
Oct 15, 2016
The space loss seems happen only when the struct{} is the very last member of the struct.
|
This is due to the fix for #9401. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have a use case where it would be useful to have a field inside of a struct that gets changed in type from something to type struct{} -- and then no longer takes up space (I want to use golang structs like protobuf message definitions).
When I checked my assumption however, I find a surprise: when the struct{} field is alone, it doesn't take up any space, as expected. But when the struct{} field is with another member, then it takes up 8 bytes. Ouch! It seems like an opportunity for optimization has been missed.
The text was updated successfully, but these errors were encountered: