Reliably determine RAM consumption of MATLAB variables

조회 수: 23 (최근 30일)
Matt J
Matt J 2024년 2월 29일
편집: Matt J 2024년 3월 1일
I am looking for a reliable way to determine how much RAM is devoted to Matlab variable data at a given moment. The whos() command does not work, because it doesn't account for copy-on-write sharing. For example, this code results in 2MB of Matlab data, but whos() counts it as 4MB,
A=rand(512);
B=A;
whos A B
Name Size Bytes Class Attributes A 512x512 2097152 double B 512x512 2097152 double
Likewise the memory() command is not reliable, because it requests a memory tally from the operating system, whose estimate can fluctuate from moment to moment depending on what the operating system is doing in the background.
There must be a way to do this, right?
  댓글 수: 14
Matt J
Matt J 2024년 2월 29일
편집: Matt J 2024년 3월 1일
@Walter Roberson I don't know if you're referring to a doc, but it still doesn't resolve the contradiction I presented to you in my previous post. According to your formula, m3 is correct, but that means memory() gave unreliable results. Which do we trust, and why?
Matt J
Matt J 2024년 3월 1일
편집: Matt J 2024년 3월 1일
@Walter Roberson the fact that ValuesForCopy exists doesn't prove that griddedInterpolant legitimately takes up twice as much memory. They could be shallow copies of one another. In fact, it seems the likely explanation for why memory() is a factor of 2 in disagreement with whos().

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

답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by