Re:Arena Allocator Tips and Tricks
by matheusmoreira on Wednesday September 27, 2023 @06:44AM
(#37672814)
> For the most part is useful for high performance numerical code, and less advantageous for typical pointer chasing stuff.
Yeah. I've read that the aliasing rules and features like restrict were introduced to C because Fortran had them.
> the safest way to implement a custom allocator is to make sure that the compiler can't see through it
Makes sense.
> launder your pointers through appropriate inline asm
This is a really neat trick indeed. I learned a lot today.
Making sure that you respect all the underspecified, obscure, and often contradicting rules is not easy, so if you prefer to disable strict-alias, you have my sympathy. For the most part is useful for high performance numerical code, and less advantageous for typical pointer chasing stuff.
From the practical point of view, the safest way to implement a custom allocator is to make sure that the compiler can't see through it, so separate compilation and no LTO and/or launder your pointers through appropriate inline asm.
[1] but other 'anonymous' sources, like mmap, would also work in practice.