Reliably determine RAM consumption of MATLAB variables

22 vues (au cours des 30 derniers jours)
Matt J
Matt J le 29 Fév 2024
Modifié(e) : Matt J le 1 Mar 2024
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 commentaires
Matt J
Matt J le 29 Fév 2024
Modifié(e) : Matt J le 1 Mar 2024
@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 le 1 Mar 2024
Modifié(e) : Matt J le 1 Mar 2024
@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().

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by