I have an ArrayList(T) that I cast to ArrayList(u8). Now I have a runtime-known Alignment, and a slice of bytes that I want to safely append to that ArrayList (I want to cast the list back to ArrayList(T) after). Thing is that I can't cast it to an ArrayListAligned because it requires comptime-known alignment which I don't have. How do I manage that?
#Operate on an array list of runtime-known alignment
1 messages · Page 1 of 1 (latest)
Perhaps the arraylist is the wrong level for doing type punning. Might be an XY problem.
I don't think it is. There's no way for me to get the type at that point, because that would require me to store it at runtime, and as far as I'm aware that's impossible
Correct, types don't exist at runtime. A tool for that is one of various tactics to generate or author type ids.
Another tactic is what C allocators use, which is everything is put at with common superset alignment.
Not clear why you're wanting to cast the collection. I may be better to look into casting a slice for a given operation.
yeah, I just pass around typeIds but they don't allow me to reconstruct the actual type. I'm pretty sure that I can do some raw memory tricks and get it to work, but I don't know how
ArrayList(ArrayList(u8)) is just a way to store many ArrayLists of different types. But to use them, I need to downcast them to their original type, or, at least, their original alignment
Looks like you're reinventing an ECS, so probably good to look at a few other existing Zig ECS's to see how they do it.
Looks like rawAlloc does not require comptime alignment so i'll just probably make my appendSliceRuntimeAlignment
Different align it's just % operations in non-optimized variant