Re:Why Rust helps even if you have to use a lot of `unsafe`
by soulbadguy on Wednesday August 02, 2023 @08:49PM
(#36979921)
> Unlikely, because the allocator would need to know things only the compilers knows
Such as ?
Re:Why Rust helps even if you have to use a lot of `unsafe`
by flohofwoe on Thursday August 03, 2023 @02:38AM
(#36982177)
The allocator can't just work with a size and alignment, it also needs to know the internal structure of objects so that it can arrange them differently (maybe to remove padding bytes, maybe to turn arrays-of-structs into structs-of-arrays. And in turn the compiler needs to know how the 'allocator' has rearranged things in order to generate the code which accesses the data.
I also wasn't thinking about moving parts of a struct out into heap allocations, that would be worse. Instead think about whether a sum type is actually necessary, even if it is convenient.
Some of that could probably be solved with comptime code (like Zig's MultiArrayList container I mentioned above).