Does an object from a handle-inherited class compresses data?
Afficher commentaires plus anciens
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 commentaires
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.
Masoud Ghaderi Zefreh
le 9 Août 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Handle Classes dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!