4 ms·
interesting, why wouldn't it work well with those types? how would an union help?
by entelechy 9y ago
interesting, why wouldn't it work well with those types?
how would an union help?
- daemin 9y agoSo 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.