The background
I am working on an ECS in C++ for fun and I am trying to make it as efficient as possible. One of the optimisations I am striving to implement is to minimise cache misses by storing the components contiguously in the memory.
Since I want to expose the interface to Lua, I cannot use all the compile time goodness C++ offers. The tough part about it is that I don't know the size of the objects at the compile time. As I understand it, I can't just use std::vector<BaseComponent>
and not experience object slicing.
TL;DR – The question
How do I store objects, whose sizes are known only at runtime, contiguously in the memory? The sizes of the objects in one container are identical.
Best Answer
new
to initialize objects.If you want the memory allocated to be aligned as per the alignment requirements of
Object
, you may use: