Show memory options in Matlab working on Mac platform

조회 수: 45 (최근 30일)
Jeena
Jeena 2013년 6월 11일
편집: Walter Roberson 2023년 8월 31일
Hi all,
I am running Matlab R2012b (64 bit) on a Mac OS (version 10.8.2) computer. I am working with large arrays and like to know the memory usage by Matlab. I have tried 'memory' before on Windows platform and it always worked perfectly ... But when I typed 'memory' in the workspace, it showed the following error
" memory
Error using memory
Function MEMORY is not available on this platform. "
Can anyone help me figure out the problem... When I typed 'help memory' it displayed all information about memory function similar to any help function. Also I can see the function 'memory' in the Matlab documentation which comes along with Matlab... but when I typed 'memory' in the workspace, it showed me an error....
Any help will be greatly appreciated ...
Thanks,
Jeena

채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 11일
Expand the Tips at the bottom to see,
The memory function is currently available on Microsoft® Windows systems only.
And unfortunately you will also find that feature('memstats') is only on MS Windows as well. There is no equivalent functionality in MATLAB for OS-X or Linux.
You can switch to a terminal window and use "top" at the shell prompt to have a look at memory stats.
  댓글 수: 3
Grant Schmick
Grant Schmick 2020년 4월 2일
Has the capability to increase allocated memory now (in 2020) been added? 'Cuz it sure ain't in 2018B. Running 'memory' gives the same result as in 2013. If I had known Mac users were second-class customers I would have gotten a PC.
Walter Roberson
Walter Roberson 2020년 4월 2일
I do not know of any change in memory allocation for R2020a.
Running 'memory' gives the same result as in 2013.
Which is to say that memory() says that it is only supported on Windows.
memory() has nothing to do with allocating memory, only with reporting memory statistics.
On my Mac, when I have turned off the preference to limit memory allocation to amount of RAM, I have seen sessions with more than 90 gigabytes allocated, on my 32 gigabyte machine. "90" was by no means a limit; that is merely the point at which I get tired of my machine swapping to disk, and I kill the program.
How much memory do you need, with how much RAM? And do you have a really fast disk to swap to? (Swapping to SSD is, in general, not recommended, due to the limites number of write cycles that SSD has. However if you have a smart SSD and your SSD is large compared to the amount of memory you will be swapping, then it might be acceptable -- especially if you are willing to treat the SSD as sort of a "consumable" ... some SSDs are pretty inexpensive and it might be worth it.)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Ian
Ian 2017년 6월 29일
편집: Walter Roberson 2023년 8월 31일
Several cmdline tools for determining physical memory on Macs.
I use:
[status, cmdout]=system('sysctl hw.memsize | awk ''{print $2}''')
google "MacOS sysctl" and "MacOS system_profiler for more info.
  댓글 수: 2
Mr M.
Mr M. 2018년 4월 28일
편집: Walter Roberson 2018년 4월 28일
[status, cmdout]=system('sysctl hw.memsize | awk ''{print $2}''')
-bash: syntax error near unexpected token `('
Walter Roberson
Walter Roberson 2018년 4월 28일
You need to execute the command inside MATLAB.

댓글을 달려면 로그인하십시오.


Michael Burke
Michael Burke 2020년 1월 27일
I created a simple function for this:
function memoryForMac()
% This function will return the memory used by MATLAB on the MAC
%
%% First get the version of MATLAB
curVer = version('-release');
%% get the PID for MATLAB
sysStr = ['ps -o ppid,command |grep ',curVer,'.app'];
[status,verStr] = system(sysStr);
if (status ~= 0)
error('MATLAB was not found: That is odd since you are in MATLAB');
end
%% Get where the string is located
% Format looks like: interested in PPID
% PPID COMMAND
% 4151 /Applications/MATLAB_R2019b.app/bin/maci64/matlab_helper /dev/ttys000 yes
slash = findstr('/',verStr);
pidStr = verStr(1:slash(1)-1);
%% Now get the memory string
sysStr = ['top -pid ',pidStr,' -l 1 -stats MEM'];
[status,info] = system(sysStr);
if (status ~= 0)
error('Invalid PID provided')
else
% now parse out the memory
memLoc = findstr(info,'MEM');
MEM = info(memLoc+5:end-1);
fprintf('Total memory used: %s\n',MEM);
end
  댓글 수: 2
Rodrigo
Rodrigo 2023년 1월 17일
Sir you're doing the Lord's work
Venky Kanniganti
Venky Kanniganti 2023년 1월 26일
편집: Venky Kanniganti 2023년 1월 26일
I pray that you have spread your progeny far and wide

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by