A different (probably slightly cheaper) hack to get a safe copy of an array is:
A = X; A(1) = A(1);
Then one can evilly edit A in-place in a mex file without accidentally editing other arrays like X. However, the docs tell us never to edit arrays from input arguments in place, so a future version of Matlab could be cleverer and still break things. I wish their mex API would provide a supported way to edit things in-place. Native Matlab code
does allow inplace editing:
A = fun(A);
If function fun is defined that way too, A can be altered in-place by native matlab code, but not (officially) by mex functions.