containers.Map
개체는 다른 개체와 마찬가지로 Matlab 개체입니다. 내부적으로 이것은 몇 가지 추가 액세스 제어 및 함수 매핑이있는 Matlab 구조로 구현됩니다.
struct
명령을 사용하면 Matlab에 원시 구조를 표시 할 수 있습니다. 일반적으로 권장되지 않으므로 경고 메시지가 표시됩니다. 그러나 클래스의 구조보기는 전체 내용을 표시하며 정확하게 whos
호출에 반영됩니다.
일부 예제 코드는 다음과 같습니다 :
%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')
(경고 메시지를 제거한 후) 위의 스크립트의 결과는 다음과 같습니다
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
나는이 관련 질문이 도움이 될 수 있다고 생각 : http://stackoverflow.com/questions/2388409/how-can-i-tell-how-much-memory-a-handle-object-uses-in-matlab](http://stackoverflow.com/questions/2388409)/how-can-i-tell-how-much-memory-a-handle-object-in-in-matlab)을 사용하는 것이 좋습니다. 감사합니다. @horchler! – horchler
그것은 완벽하게 작동했습니다. http://stackoverflow.com/a/2389080/2338750에 대한 주석이 올바르다 고 가정하면 구조체로의 변환이 많은 메모리를 차지하지 않는다는 것을 간단히 설명하는 것처럼 보입니다. Matlab에서는 이러한 종류의 트릭이 필요하다는 것이 매우 이상하다고 생각합니다. –