3 ms·
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 alloca
by widdershins 3y ago
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.
- soulbadguy 3y agoa good allocator could mitigate most of the allocation effects
- flohofwoe 3y agoUnlikely, 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).
- soulbadguy 3y ago> Unlikely, because the allocator would need to know things only the compilers knows Such as ?
- flohofwoe 3y agoSuch a 'smart 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, I think in most situations that would be worse than having to deal with padding. Instead at least have the programmer think about how the internal memory layout of sum types might affect performance in specific situations instead of just using them everywhere and in mass because they are convenient.
- gpderetta 3y agoI think parent meant transforming a vector<A+T> into vector<A>*vector<T>