1

Hi I'm using an object with superclass dynamicprops & matlab.mixin.Copyable

Now I would like to now the size (memorywise) of each of the dynamic properties. I tried stuff like whos and getfield. But it seems like I have a very hard time to find something.

I know that people strugle to get exactly this for handle objects, which this is one of them... But I was wondering if somebody has a solution on that nevertheless.

yours magu_

Amro
  • 123,847
  • 25
  • 243
  • 454
magu_
  • 4,766
  • 3
  • 45
  • 79

1 Answers1

0

You could use the properties function to get a list of properties exposed by an object. The same can be done using metaclass. You can then iterate over them and use x.(p) syntax to access each by name (dynamic field names). You would determine the size memory-wise the same way you do any other variable (size/class or whos).

Note that you might need to recursively traverse the properties in case they are containers themselves (objects, structs, cell-arrays).

Amro
  • 123,847
  • 25
  • 243
  • 454
  • Thx for the answer but I'm not sure if this really get's all the info. This code: clear all n = 1e6; A = cell(1,n); whos A B = A; for i=1:n B{i} = 1; end whos B C = zeros(1,n); whos C produces A = 4MB; B = 68 MB; C = 8 MB. There must be some overhead somewhere meaning a Cell needs more than merly the structure itself + the data. I think Matlab uses some mxArray informations to store what kind of Datatype it is. Maybe ths accounts for the rest – magu_ Jul 25 '13 at 09:39