フィルターのクリア

the Problem of Distribution memory of MATLAB struct?

5 ビュー (過去 30 日間)
deng
deng 2016 年 6 月 4 日
編集済み: James Tursa 2016 年 7 月 1 日
clear all
clc
testStruct.a=int8(10);
a=int8(10)
whos testStruct
whos a
the result is:
a =
10
Name Size Bytes Class Attributes
testStruct 1x1 125 struct
Name Size Bytes Class Attributes
a 1x1 1 int8
Variable a takes up 8 bytes, however, testStruct.a takes up 125 bytes。why? my email:dengshuaiqi@163.com,think you very much。
  1 件のコメント
James Tursa
James Tursa 2016 年 7 月 1 日
編集済み: James Tursa 2016 年 7 月 1 日
The whos result is misleading for this comparison. For the following discussion the numbers cited assume a 64-bit system and that the overhead for a MATLAB variable is 124 bytes (this is approx).
First, every MATLAB variable has an overhead structure called an mxArray that contains information such as class, size, data pointers, sharing pointers, etc. So for variable "a" above, the data for "a" is only showing 1 byte, but the mxArray for this variable is taking up an additional 124 bytes of memory. So the total amount of memory actually used by variable "a" is 125 bytes. (actually probably more due to memory alignment effects)
For the struct testStruct, it too has this mxArray overhead. So there is 124 bytes right there. Then the data area of this struct is actually mxArray pointers, another 8 bytes. Then there is memory for the field name "a", so another 2 bytes minimum for that. Then the data itself is actually a MATLAB variable, so the overhead and data for that come to another 125 bytes. So the total for the struct testStruct is actually 124 + 8 + 2 + 125 = 259 bytes.
Bottom line is that you can't really compare the whos result of structs to numeric variables since whos does not tell you the whole memory story, it only reports on the data areas.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 4 日
The structure as a whole takes up 125 bytes, not just the .a field of the structure.
The structure includes the overhead to list all of the field names and the types and sizes of each of the fields.
  6 件のコメント
deng
deng 2016 年 6 月 6 日
I see.Think you very much.
Walter Roberson
Walter Roberson 2016 年 7 月 1 日
deng comments to my original Answer:
hello, problem of memmapfile function. think you very muchu. http://www.mathworks.com/matlabcentral/answers/293260-problem-of-memmapfile-function

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by