Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think (s)he meant sorted alphabetically, but rather, sorted in such a way as to minimize memory usage, ie: packed.

This is obviously not the default in C, but can be enabled via compiler extensions. It's also important that the compiler doesn't automatically do this since structs of the same type can be of different sizes. In order for this to work, the memory layout needs to be as originally defined in order to be correct. For an example of this see the simple dynamic string library used in redis.



I don't think gcc or clang can reorder structs, or do they?


Yep, you're right, I was mistaken, it's been a while since I looked at all the extensions and I thought reordering was one of them, I should have rechecked before I made my comment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: