If you are only building for x64 native, this code is perfectly fine since it is always 16-byte aligned.
class A { public: XMVECTOR vect; }; void fun(void) { A* a = new A; XMVECTOR localVect = a.vect; }
To make it portable to x86 or ARM (32-bit), you have one of three choices:
- Create an overloaded new for the class A that uses __aligned_malloc(,16);
- Create a global new overload that does this (which is not recommended)
- Just use XMFLOAT4 or it's kin and explicitly use XMLoadFloat4/XMStoreFloat4
The following code results in the identical compiled code as the block above except that one movaps is now a movups:
class A { public: XMFLOAT4 vect; }; void fun(void) { A* a = new A; XMVECTOR localVect = XMLoadFloat4( &a.vect ); }
As such, there's no point in messing around with aligned allocations unless it's trivial to do for some other reason (such as DirectX Tool Kit's use of the pImpl idiom which means we might as well align the internal class allocations to make it convenient).
If your complaint is just the extra work it takes to use XMVECTOR correctly with respect to the alignment, you could take a look at using SimpleMath from the DirectX Tool Kit.