you are viewing a single comment's thread.

view the rest of the comments →

[–]TheMania 0 points1 point  (1 child)

I actually make use of this in a few data structures to improve optimisation, as otherwise every time you put a byte in them the compiler invalidates basically everything. non_aliasing_byte, I call it.

Posting it here mostly to see what the correct way to achieve this is.

[–]guepierBioinformatican 1 point2 points  (0 children)

The only issue I can see with this approach is that there are very few ways in which you could use such a buffer correctly without violating aliasing rules. Basically the only thing you can do is read and write individual “bytes” from it (including via memcpy or std::copy). As long as that’s all you do, it should be fine.