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

This won't work well with types that need alignment. It might be better not to have the internal buffer of characters but instead have an anonymous union of both left and right types.

Also Expected is not quite the same thing as this. This Maybe and Either is like Expected but with the ability to call .then() on it to do further processing.



interesting, why wouldn't it work well with those types?

how would an union help?


So one of the reasons is that it's following a bool variable, which size is not fixed, but are usually 1 byte. So even if the class itself was aligned the buffer within would be unaligned. The other is that the alignment of a char buffer is 1 by default.

This can actually lead to crashes in the processor when it is using aligned functions (like SSE) but the data is unaligned.

If a union is used instead it should be aligned to the biggest alignment of its members. Then if it's put at the start of the class as the first variable, it should make the class aligned to the same value and not waste space on padding.




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

Search: