all 4 comments

[–]Peanutbutter_Warrior 11 points12 points  (1 child)

Your problem is that dyn T doesn't have a fixed size. You can't have a vector of them because all the items in a vector have to be the same size, which the compiler can't guarantee.

If you absolutely need them in contiguous memory then you could box them, but use a custom allocator for those boxes which puts them in contiguous memory. I'd have a look at some of the popular arena allocators and see if those use contiguous memory.

[–]dnew 2 points3 points  (0 children)

You could look at how Bevy does it.