Name Size Bytes Class Attributes
Laptops 4x1 369 cell
Structures
S.A = [];
B = whos('S');
B.bytes - 60
ans =
64
Compute the memory needed for a structure array as follows:
32-bit systems: fields x ((60 x array elements) + 64) + data
64-bit systems: fields x ((112 x array elements) + 64) + data
On a 64-bit computer system, a 4-by-5 structure Clients with fields Address and Phone
uses 4,608 bytes just for the structure:
2 fields x ((112 x 20) + 64) = 2 x (2240 + 64) = 4608 bytes
To that sum, you must add the memory required to hold the data assigned to each field. If
you assign a 25-character vector to Address and a 12-character vector to Phone in each
element of the 4-by-5 Clients array, you use 1480 bytes for data:
(25+12) characters 2 bytes per char 20 elements = 1480 bytes
Add the two and you see that the entire structure consumes 6,088 bytes of memory.
Example 1 – Memory Allocation for a Structure Array
Compute the amount of memory that would be required to store the following 6-by-5
structure array having the following four fields on a 32-bit system:
A: 5-by-8-by-6 signed 8-bit integer array
B: 1-by-500 single array
C: 30-by-30 unsigned 16-bit integer array
D: 1-by-27 character array
Construct the array:
A = int8(ones(5,8,6));
B = single(1:500);
C = uint16(magic(30));
How MATLAB Allocates Memory