Variable size: does it reflect real size after computation finishes?
Afficher commentaires plus anciens
Hi all,
I have a program which produces a 40227 by 50 double matrix. I'd like to optimize storage so I want to check total memory usage. It is in structural variable "canti". If I run whos, MATLAB shows:
K>> whos
Name Size Bytes Class Attributes
INPname 1x60 120 char
a 1x1 8 double
ans 1x1 1 logical
bondL1 1x1 8 double
bondL2 1x1 8 double
bondR1 1x1 8 double
bondR2 1x1 8 double
canti 1x1 112 canbeam
However, structural variable "canti" contains a few large variables as follows:
K>> canti.dis
ans =
inpt: [40227x1 double]
val: [40227x50 double]
full: [40227x50 double]
trial: [40227x50 double]
Why would "canti" only uses 112 bytes of memory while it contains variables of 40227 by 50 matrix? According to my test, if I do:
>> a = rand(40227, 50);
>> whos
Name Size Bytes Class Attributes
a 40227x50 16090800 double
A 40227 by 50 double should cost 16090800 bytes in memory, which is 15.3454 MB. If MATLAB is not showing the real memory usage for some reason, then how can I check the memory usage during and after my program?
Many thanks!
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 26 Mai 2017
Notice you have
canti 1x1 112 canbeam
here, "canbeam" is the data class of the variable. It is not struct, not cell array, not numeric, but rather "canbeam", which is not a Mathwork-supplied data type. It must be an object oriented object from a class you have provided.
I suspect, from the size, that canbeam is a handle class. If so then because you can have multiple copies of the same handle, it would be incorrect to count the referenced memory against the handle: the 112 bytes is the size of the handle itself.
1 commentaire
Xh Du
le 30 Mai 2017
Catégories
En savoir plus sur Variables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!