The containers.Map
object is a Matlab object like any other. Under the hood these are implemented as a Matlab structures with some additional access controls and function mappings.
You can force Matlab to show you the raw structure using the struct
command. This throws a warning, as it is usually not recommended. However, the structure view of the class shows the complete contents, and is accurately reflected in a whos
call.
Some example code is below:
%Initialize map and add some content
res_Map = containers.Map;
for ix = 1:1000
res_Map(sprintf('%05d',ix)) = ix;
end
%Look at the memory used by the map
disp('Raw who: always 112 Bytes for Map')
whos('res_Map')
%Force the map into a structure, and look at the contained memory
mapContents = struct(res_Map);
disp('Look at the size of the map contents, reflect true size')
whos('res_Map','mapContents')
%Add additional contents and check again.
for ix = 1001:2000
res_Map(sprintf('%05d',ix)) = ix;
end
mapContents = struct(res_Map);
disp('Look at the size of the map contents, reflect true size')
whos('res_Map','mapContents')
The result of the above script (after removing the warning messages) is shown below:
Raw who: always 112 Bytes for Map
Name Size Bytes Class Attributes
res_Map 1000x1 112 containers.Map
Look at the size of the map contents, reflect true size
Name Size Bytes Class Attributes
mapContents 1x1 243621 struct
res_Map 1000x1 112 containers.Map
Look at the size of the map contents, reflect true size
Name Size Bytes Class Attributes
mapContents 1x1 485621 struct
res_Map 2000x1 112 containers.Map