 <p>That is correct, the data buffer for the original <code>A</code> is destroyed by MATLAB and a new buffer is created (the same <code>mxArray</code> structure address is reused presumably by copying the new one onto the original after deallocating the original array's data buffer). <strong>This is assuming you are <em>not</em> writing to <code>prhs[i]</code> in you MEX file!</strong></p> <p>You can see this with <code>format debug</code>. You will observed that the output <code>mxArray</code> has the same address, but it's data buffer has a different address, so it has clearly reallocated the output array. This suggests that the original buffer is deallocated or queued to be deallocated.</p> <p>Starting with the output for a change, of the file <code>testMEX.mexw64</code> that takes the first half of the input array's first row and copies it into a new array:</p> <pre> >> format debug >> A = rand(1,8) A = <b>Structure address = efbb890</b> m = 1 n = 8 <b>pr = 77bb6c40</b> pi = 0 0.2581 0.4087 0.5949 0.2622 0.6028 0.7112 0.2217 0.1174 >> A = testMEX(A) A = <b>Structure address = efbb890</b> m = 1 n = 4 <b>pr = 77c80380</b> pi = 0 0.2581 0.4087 0.5949 0.2622 </pre> <p>Note that <code>pr</code> is <strong>different</strong>, meaning that MATLAB has created a new data buffer. However, the <code>mxArray</code> "Structure address" is the same. So, at the minimum, the old data buffer will be deallocated. Whether or not the original <code>mxArray</code> structure is simply mutated or a new <code>mxArray</code> is created is another question (see below).</p> <hr> <p><strong>Edit:</strong> The following is some evidence to suggest that an entirely new <code>mxArray</code> is created and it is copied onto the old <code>mxArray</code></p> <p>Add the following two lines to the MEX function:</p> <pre><code>mexPrintf("prhs[0] = %X, mxGetPr = %X, value = %lf\n", prhs[0], mxGetPr(prhs[0]), *mxGetPr(prhs[0])); mexPrintf("plhs[0] = %X, mxGetPr = %X, value = %lf\n", plhs[0], mxGetPr(plhs[0]), *mxGetPr(plhs[0])); </code></pre> <p>The result is:</p> <pre> prhs[0] = EFBB890, mxGetPr = 6546D840, value = 0.258065 plhs[0] = <b>EFA2DA0</b>, mxGetPr = 77B65660, value = 0.258065 </pre> <p>Clearly there is <strong>a temporary <code>mxArray</code></strong> at EFA2DA0 containing the output (<code>plhs[0]</code>), and this <code>mxArray</code> header/structure is entirely copied onto the old <code>mxArray</code> structure (the one as <code>A</code> in the base MATLAB workspace). Before this copy happens, MATLAB surely deallocates the data buffer at <code>6546D840</code>.</p> <p><strong>testMEX.cpp</strong></p> <pre><code>#include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mxAssert(nrhs == 1 &amp;&amp; mxGetM(prhs[0]) == 1, "Input must be a row vector."); double *A = mxGetPr(prhs[0]); size_t cols = mxGetN(prhs[0]); size_t newCols = cols / 2; plhs[0] = mxCreateDoubleMatrix(1, newCols, mxREAL); for (int i = 0; i &lt; newCols; ++i) mxGetPr(plhs[0])[i] = A[i]; mexPrintf("prhs[0] = %X, mxGetPr = %X, value = %lf\n", prhs[0], mxGetPr(prhs[0]), *mxGetPr(prhs[0])); mexPrintf("plhs[0] = %X, mxGetPr = %X, value = %lf\n", plhs[0], mxGetPr(plhs[0]), *mxGetPr(plhs[0])); } </code></pre>