| There's no reason an allocator should ever trip over strict aliasing rules. malloc() returns an address. The user code writes a value, and then reads a value of the same type. No problem. Later, malloc() returns the same address. The user code writes a value of another type then reads a value of that same type. Again, no problem. There's no aliasing going on here. The act of writing a value of a different type tells the compiler that the lifetime of the previous object has ended. There's no special magic required. Strict aliasing is about situations where we write a value of one type, and then attempt to read a value of a different type from the same location. If you want to do that, then you have to be extremely cautious. But memory allocators don't do that, so it's not an issue. (Obviously just talking about C here, or POD in C++ terms. If you are dealing with C++ objects with destructors, then you have an extra layer of complexity to deal with, but again that's nothing to do with aliasing.) |
afaik only memcpy has that magic property, so I think parent is almost correct.
So in the new, pool_new: This sets the effect type of the chunk block to 'Chunk'Later in pool_alloc:
result has effective type 'Chunk'In user code:
User code would need to look like this: