Prev: Creating static libs to use in mex
Next: short pause
From: Dag Lindbo on 25 May 2010 12:26 Hello! I'm looking for a way for a way of determining the size of a matlab class instance, but can't seem to come up with anything. That is, I have a handle class that contains some properties and I'd like to be able to see the total amount of memory allocated to hold an instance of this class (including all the memory allocated to hold all properties). Is there a function for this? Doing 'whos' will not do give the whole thing: >> whos Name Size Bytes Class mat 2048x2048 33554432 double hmat 1x1 112 hmat_lr These two variables represent the same matrix, but the latter in a hierarchical way. Again, all I want to do is get the number of bytes allocated to hold "hmat". The only solution I've come up with so far is to write both variables to the hard drive and compare the resulting file sizes... This, however, is unreliable due to the compression applied. Thanks for any thoughts on this! /Dag
From: James Tursa on 25 May 2010 13:25 "Dag Lindbo" <no(a)spam.com> wrote in message <htgtn1$bs2$1(a)fred.mathworks.com>... > > The only solution I've come up with so far is to write both variables to the hard drive and compare the resulting file sizes... This, however, is unreliable due to the compression applied. Not a great solution, but you could try writing it out in an older format to avoid the compression. James Tursa
From: Matt J on 25 May 2010 13:42 Something like the following, perhaps: S=warning('off'); myStruct=struct(myObject); whos myStruct warning(S);
From: Steven Lord on 25 May 2010 13:54 "Dag Lindbo" <no(a)spam.com> wrote in message news:htgtn1$bs2$1(a)fred.mathworks.com... > Hello! > > I'm looking for a way for a way of determining the size of a matlab class > instance, but can't seem to come up with anything. Since you're referring to "size" as in "amount of memory used to store", in general, this may not be possible. a = ones(100); b = a; c = a; d = a; Until you modify one of a, b, c, or d they're all "pointing" to the same block of data storing a 100-by-100 matrix of 1's. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/brh72ex-2.html#brh72ex-8 How much memory would you consider a to contain? All the memory required to store the 100-by-100 matrix, or only part of it because it's sharing with b, c, and d? I don't remember if this behavior also holds for objects, but even if it doesn't it could hold for the matrices and arrays stored in that object's properties. If there was a way to generate such information, how would you use that information? Perhaps there's some alternate approach to do what you want without needing to generate this information. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Dag Lindbo on 25 May 2010 16:25
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hth25h$h30$1(a)fred.mathworks.com>... > Something like the following, perhaps: > > > S=warning('off'); > myStruct=struct(myObject); > > whos myStruct > > warning(S); Matt, thanks for this suggestion. It goes some way towards what I'm looking for -- but my class instance contains instances of the same class (recursively in the ctor). So basically, I can tail out the recursion and convert each object to a struct. /Dag |