Take class1 as
classdef class1
properties
prop1 cell = {1};
prop2 string = 'string';
prop3 struct = struct('field1',[1 1],'field2','string');
end
end
The instance obj1 of class1
obj1 = class1
takes 634 bytes of memory (120 bytes for cell + 12 for string + 380 for struct + 112 for ?? = 634). Now take class2 as
classdef class2
properties
prop1
prop2
prop3
end
methods
function out = class2
[out.prop1,out.prop2,out.prop3] = deal(class1);
end
end
end
obj2 being an instance of class2 takes 1902 bytes of memory (634 bytes for each class1 instances * 3 = 1902).
Finally, take class3 inherited from class handle
classdef class3 < handle
properties
prop
end
methods
function out = class3
out.prop = class2;
end
end
end
Now,
obj3 = class3;
takes only 8 bytes, whereas if you store obj3.prop in a variable you'll see that it takes 1902 bytes. My question is, how is this happening? Can I reduce the memory usage by storing my data in objects of this type?

댓글 수: 2

José-Luis
José-Luis 2017년 8월 8일
편집: José-Luis 2017년 8월 8일
Never used Matlab classes, so take what I'm saying with a grain of salt.
It sounds like you are storing a reference to the object an not the object itself. There probably is no compression happening,
That being said, 8 bytes sounds smallish for a pointer.
What you say is actually correct. I asked a colleague and he also told me the same earlier today. Nothing is compressed. Thank you

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam
Adam 2017년 8월 8일
편집: Adam 2017년 8월 8일

0 개 추천

Memory reported for handle classes tends to be totally un-useful. I don't know why, but it always shows up as 8 bytes, but that doesn't mean that is really how much memory is taken up by all its components. I guess that is just the single memory address byte usage for the class 'pointer'. The rest of the memory usage is hidden, or at least I have never found a way within Matlab of seeing my memory usage with handle class objects.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by