How the command whos works

16 次查看(过去 30 天)
I wonder how the command whos works. I have found:
Memory Usage Reported By the whos Function. The whos function displays the amount of memory consumed by any variable. For reasons of simplicity, whos reports only the memory used to store the actual data. It does not report storage for the array header, for example.
When I campute the memory used, for example, by a structure, it seems to me that head is included in the computation. For example, the formula for memory used structure array is fields x ((112 x array elements) + 64) + data that includes header. This memory corresponds exactly to the quantity in bytes given by the command whos.
I should conclude that whos gives the amount of memory including header. Where am I wrong?
  3 个评论
Anna
Anna 2020-5-8
I find in the documentation "How Matlab Allocates Memory" (https://se.mathworks.com/help/matlab/matlab_prog/memory-allocation.html#brh72ex-14) for release 2020a. That's why I thought that it was actual.
Steven Lord
Steven Lord 2020-5-11
That page has at least one piece of out-of-date information on it. Complex arrays are no longer stored as separate pieces as of release R2018a. I'll report that to the documentation staff.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-5-8
This memory corresponds exactly to the quantity in bytes given by the command whos.
However you have to add to that the header size to hold information about the variable.
>> abc = 0
abc =
0
>> whos abc
Name Size Bytes Class Attributes
abc 1x1 8 double
abc is a double precision variable with one entry, and each double precision value needs 8 bytes. 1 row * 1 column * 8 bytes per entry = 8 bytes.
But storage is also occupied to hold the information that abc is 1 x 1, and that it is class double, and that it is not complex-valued, and that it is not global. whos does not report about that space.
  1 个评论
Anna
Anna 2020-5-11
Thank you for your answer! If I understand correct it is two different kind of headers. One is the header, as you say, to hold information of the variableand onterh is the header of the structure (that is includes in the whos command).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by