# Can I use memcpy() with XMMATRIX?

I.e. can I do this:

XMMATRIX dxMat;
Matrix myMat;
std::memcpy(&myMat, &dxMat, sizeof(XMMATRIX));
std::memcpy(&dxMat, &myMat, sizeof(XMMATRIX));


Matrix is my own class which contains 16 contiguous float variables (only). Also can I do the same with my vector class (4 floats) and XMVECTOR?

In other words, is XMMATRIX a POD?

• memcpy should technically work. You just need to make sure that your data structure matches the data structure you're copying from exact, or you may run into some odd results. – user39686 Jan 6 '14 at 20:08

struct XMMATRIX {

But keep in mind that using memcpy is error prone and could introduce hard to find bugs. I suggest you use a constructor in your Matrix class that takes XMMATRIX, and copy it internally. This way you take advantage of: 1. Type safety, instead of the void* that is passed to memcpy. 2. Your code won't have memcpy all over the place. So less bugs, and even if you used memcpy inside the constructor and have a bug you will only solve it once. According to the DRY principle.