I am looking for an equivalent of the data returned by memory on windows platform on unix, in matlab.
I am aware of the possibility of using unix(\'vm_stat\'), but t
Call command 'free' and parse the results. This works on linux
[r,w] = unix('free | grep Mem');
stats = str2double(regexp(w, '[0-9]*', 'match'));
memsize = stats(1)/1e6;
freemem = (stats(3)+stats(end))/1e6;
The output is in Gbytes. The last number free returns is 'cached' memory used by the OS, e.g. dynamic libraries. It can in general be used, but you can decide to leave it out and just use what free reports as 'Free' - the third numerical field in the output.
Edit On Linux, memory allocation within MATLABs mxMalloc/mxCalloc most likely simply calls malloc and friends. To get a hint that this is the case do the following experiment. In a mex file allocate an array using the following code, and return it to MATLAB:
rout = calloc(sizeof(Double),M*N);
pargout[0] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL);
mxSetM(pargout[0], m);
mxSetN(pargout[0], n);
mxSetData(pargout[0], rout);
mexMakeMemoryPersistent(rout);
You can normally use the variable returned in MATLAB. You can even clear it - this does not cause any problems. If indeed MATLAB simply uses malloc, there is no way that I know of in which they can enforce physically contiguous memory.
I know that you can not run the above code on Windows though. This code crashes MATLAB. Of course, you should not do that in your codes. It merely illustrates the point.