News for hackers. Stuff that matters.
Re:Why Rust helps even if you have to use a lot of `unsafe` by widdershins on Wednesday August 02, 2023 @11:13AM (#36971994)
That depends on the sizes of the objects. If the objects in the union are generally small, cache coherence is better than if you have polymorphic objects allocated on the heap.
Re:Why Rust helps even if you have to use a lot of `unsafe` by soulbadguy on Wednesday August 02, 2023 @11:46AM (#36972495)
a good allocator could mitigate most of the allocation effects
Re:Why Rust helps even if you have to use a lot of `unsafe` by flohofwoe on Wednesday August 02, 2023 @12:24PM (#36973067)
Unlikely, because the allocator would need to know things only the compilers knows, and the compiler in turn needs to know how the allocator lays out the data in memory?

Some of that could probably be solved with comptime code (like Zig's MultiArrayList container I mentioned above).

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.

Re:Why Rust helps even if you have to use a lot of `unsafe` by gpderetta on Wednesday August 02, 2023 @11:50AM (#36972547)
I think parent meant transforming a vector<A+T> into vector<A>*vector<T>