#Operate on an array list of runtime-known alignment

1 messages · Page 1 of 1 (latest)

finite thistle
#

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?

quartz ridge
#

Perhaps the arraylist is the wrong level for doing type punning. Might be an XY problem.

finite thistle
quartz ridge
#

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.

finite thistle
#

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

finite thistle
quartz ridge
#

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.

finite thistle
#

Looks like rawAlloc does not require comptime alignment so i'll just probably make my appendSliceRuntimeAlignment

ebon vigil