Variable size: does it reflect real size after computation finishes?
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Stephen23
2017 年 5 月 26 日
編集済み: Stephen23
2017 年 5 月 26 日
A structure does not really contain any arrays, but is a list of links to other arrays in memory (some might call this an "an array of pointers"). As such, whos correctly returns the size of the structure itself, and not of the arrays that it has links to. See:
Unfortunately the standard whos cannot read the memory size (bytes) of arrays in a structure. You could try this FEX submission:
その他の回答 (1 件)
Walter Roberson
2017 年 5 月 26 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!