2013-06-03 2 views
2

res_Map이라고하는 map이 있으며 다양한 크기의 배열 집합을 포함합니다. res_Map을 저장하는 데 사용 된 총 메모리를 찾고 싶습니다.MATLAB에서지도의 바이트 수는 얼마입니까?

아래에서 볼 수 있듯이 res_Map의 개별 요소가 수행하는 것과 달리 res_Map은 거의 메모리를 차지하지 않는 것처럼 보입니다.

res_1 = res_Map(1); 
>> whos 
    Name    Size    Bytes Class    Attributes 

    res_1   118x100   94400 double      
    res_Map   11x1    112 containers.Map 

사람이 내가 res_Map를 저장하는 데 사용되는 실제 메모리를 찾을 수있는 방법을 알고 있나요? documentation에서 이에 대한 정보를 찾을 수 없습니다.

+1

나는이 관련 질문이 도움이 될 수 있다고 생각 : 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

+0

그것은 완벽하게 작동했습니다. http://stackoverflow.com/a/2389080/2338750에 대한 주석이 올바르다 고 가정하면 구조체로의 변환이 많은 메모리를 차지하지 않는다는 것을 간단히 설명하는 것처럼 보입니다. Matlab에서는 이러한 종류의 트릭이 필요하다는 것이 매우 이상하다고 생각합니다. –

답변

3

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 
1

에 대해 matlab central에 해당하는 스크립트가 있습니다.이 스크립트는지도에서도 작동합니다.

직접 구현하려면지도의 내용을 반복적으로 검색 한 다음 struct 또는 cell의 모든 입력란을 반복해야 크기를 결정할 수 있습니다.

+0

니스. 모든 변수에 대해 진정한 메모리 사용량을 반환하는'whos' (또는 오버로드 된 버전)의 대안은 역시 좋을 것입니다. – horchler

+0

예, 그렇습니다. 꽤 놀랍습니다. 현재 (내 지식으로) 존재하지 않습니다. –

관련 문제