Prev: Creating static libs to use in mex
Next: short pause
From: Dag Lindbo on 25 May 2010 16:55 "Steven Lord" <slord(a)mathworks.com> wrote in message <hth2sr$62a$1(a)fred.mathworks.com>... > > "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, thanks for these remarks! I'm familiar with the copy semantics used in Matlab, but forgot to pose my problem properly in that context. It is for my purposes sufficient to assume that arrays are non-aliased (i.e. materialized in Matlab-speak, I think). As far as usage goes, it is for instance convenient when setting up a large computation to be able to judge how much data will be stored on disk. I see a lot of time dependent physical simulations where object orientation is natural. In particular, storing and loading objects with mat-files is an important feature. In a memory-managed environment it seems like a sensible thing to ask -- how much main memory is associated with a particular variable (yes, as a C-programmer, I see the luxury in this)? A second point is on memory usage optimization. It is common to face constraints on available memory, so people spend a lot of time and effort on compression strategies. These become harder to evaluate when matlab hides the actual size of an object in memory. It would be _great_ to have a function, say bytes(mat), returning the size in memory of an object (or even an array for starters) and zeros if the object is aliased (to-be copied if written to). With this one could code for efficient memory usage more easily and with more confidence. Hope that makes sense! /Dag > -- > 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 > |