Why does the rand function in the assignment statement within the class's property only work once?
0 个评论
采纳的回答
4 个评论
更多回答(1 个)
Named variables in MATLAB have a symbol table entry that appears to be a fixed size, and which appear to hold little more than the name and a pointer to descriptor of the variable.
Unnamed temporary variables are created all the time in MATLAB: for example A+1+B creates an unnamed temporary variable to hold the results of A+1. The pointers to those get passed around to do the real work.
A descriptor of a variable contains information about the dimensions of the variable and the class of a variable and whether it is complex or global. If the variable is not empty then there is one (possibly two historically for complex) pointers to data blocks.
When you ask for whos of a variable, the size of the variable descriptor is not included. For example
A = 1.23; whos A
will show that A is 1x1 double and 8 bytes. Each location of a double takes 8 bytes, A has exactly 1 element, 1*8=8 and whos A will report the 8. So whos reports the (occupied) size of the data blocks associated with a variable.
When you have a class that has only constant properties then there is no per-instance data storage for it. It does not need a data block for each different variable of the same type in this situation. So whos reports the bytes in the instance data blocks, which is zero bytes.
Meanwhile the descriptor for the variable contains the class name, and the class has been loaded into memory. The information such as list of method names and pointer to implementing code do not need to be stored per instance, only once for the class, and that class definition location is also where the class statics are stored. whos on an instance is not going to show the size of that shared class data anymore than it would show how much memory is allocated for the method implementations.
0 个评论
另请参阅
类别
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!