3 ms·
I object to reinterpreting bytes of one object as object of another type being C mindset. Yes, this is done sometimes if you really need it (compression being o
by bluecalm 8y ago
I object to reinterpreting bytes of one object as object of another type being C mindset. Yes, this is done sometimes if you really need it (compression being one example) but it's not really something you write everyday in C and doing it to calculate hash is just lazy.
- amluto 8y agoExcept that hashing a block of memory is likely to be much faster than hashing individual fields once there are more than a couple fields. IMO the right solution would be a special annotation on a struct that says “I want the logical value of this struct to uniquely determine the bytes of the struct’s in-memory representation.” Of course, adding such an attribute without nasty edge cases may be tricky.
- Tarean 8y agoBut this mostly matter for arrays and then an alternative optimization might be to store it as a structure of arrays. This doesn't need the padding and is more simd friendly.
- blub 8y agoThe C mindset is one of always looking for optimisations and thinking at the bit & byte level. The above solution flows naturally...