Thank you for your reply, I'd rather have a general solution though. A friend of mine informed me that most of the time the compiler does this for you, news of the same type are usually aligned in memory. Can anyone confirm this?
In any case, isn't it possible to store a pointer to a dynamically allocated vector and use casting to push back new elements?
Components shouldn't have any state so there for you should only have one component of each type and thus allignment is not that much of a matter in the componenent manager, and thus x-byte allignment will be fine.
The entity is the one that encodes all the state in the attributes that are attached to it.
The following line should force alignment for each variable declared that way, MSVC only I think GCC might have another definition
__declspec(align(SIZE)) <VarName>class __declspec(align(16)) AllignedClass{int m_data;}If you put that between class and the name of your class you should get a class that is alligned on SIZE, your best bet would be 4,16 or 32 ofcourse, D3DX defines there matrix classes as 16 byte aligned. Be aware that this can increase the memory usage of your application if you haven't layed out the data in your classes properly.
The compiler doesn't do any allignment for you, I think your friend get confused and meant that the offset within a class for a variable is based on the address of the previous one, which is true except when that variable is an alligned one. If it is both the offset and the allignment come into play in the fact that if the previous variable doesn't end on the allignment vaboundarty the compiler will pad it so that it reaches the alignment boundary, if it does nothing happens. When it has to pad you are going to waste space so becareful with aligned data types and try to place them on the alignment boundaries if you can. This sounds like a premature optimisation but it is not one, it will avoid you running out of memory when using this in restriced pools.