On Thursday, 17 May 2018 at 20:25:26 UTC, Shachar Shemesh wrote:
Obviously, Something can be an enum or a boolean. If it is,
however, then we have to perform a condition to select the
correct value. The problem with conditionals is that if the CPU
misses a guess about what they are (and in our case, the CPU is
going to miss about 50% of the time), they are extremely
expensive to evaluate.
Performance wise, a much saner approach is:
alias Something = int*;
Of course, this means our struct now has a self referencing
pointer.
What I'm getting at is that even if there are alternatives to
structs pointing at themselves, they may not be performance
wise comparable to pointers.
It's possible to do a branchless condition that chooses between
two pointers. I think if the hardware (and compiler) support it
it'll just optimize down to a "cmov".