Prev: set the interpreter property to ‘none’
Next: Q: mnrfit contains slow code, but also commented-out line saying"Do these computations but more efficiently"
From: Oleg Komarov on 14 Jul 2010 09:16 I've been playing with us's vsize when I noticed this strange (?) behaviour in the example input: clear v v(1).a{1}=sparse(magic(3)+2i*magic(3)); v(2).a{2}={struct('FA',{'a','bb'},'FB',{magic(5),{}})}; v(2).b{2}=@(x) sind(x); % Size in bytes of v is: 1998 bytes v.a; v.b; % now is: 2012 bytes Can somebody explain me why? Oleg
From: Steven Lord on 14 Jul 2010 09:26 "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message news:i1kdan$ko8$1(a)fred.mathworks.com... > I've been playing with us's vsize when I noticed this strange (?) > behaviour in the example input: > > clear v > v(1).a{1}=sparse(magic(3)+2i*magic(3)); > v(2).a{2}={struct('FA',{'a','bb'},'FB',{magic(5),{}})}; > v(2).b{2}=@(x) sind(x); > % Size in bytes of v is: 1998 bytes At this point, v(1).b is completely empty (nothing in it at all.) However, when you do this ... > v.a; > v.b; MATLAB has to display _something_ for v(1).b, so it displays (and stores in v(1).b) an explicit empty matrix, which takes up more memory than "nothing at all". > % now is: 2012 bytes > > Can somebody explain me why? Read the second sentence in the Description section of this mx-function: http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mxcreatestructarray.html -- 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: us on 14 Jul 2010 09:43 "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i1kdan$ko8$1(a)fred.mathworks.com>... > I've been playing with us's vsize when I noticed this strange (?) behaviour in the example input: > > clear v > v(1).a{1}=sparse(magic(3)+2i*magic(3)); > v(2).a{2}={struct('FA',{'a','bb'},'FB',{magic(5),{}})}; > v(2).b{2}=@(x) sind(x); > % Size in bytes of v is: 1998 bytes > > v.a; > v.b; > % now is: 2012 bytes > > Can somebody explain me why? > > Oleg oleg, now THAT would be detrimental(!)... here, we get (in accordance with the size of single fields)... clear v; v(1).a{1}=sparse(magic(3)+2i*magic(3)); v(2).a{2}={struct('FA',{'a','bb'},'FB',{magic(5),{}})}; v(2).b{2}=@(x) sind(x); f1=v.a; f2=v.b; whos v f1 f2; %{ Name Size Bytes Class Attributes f1 1x1 256 cell f2 0x0 0 double % <- strange BUT correct... v 1x2 1402 struct %} vsize(v) %{ % ------------------------- % 1402 1402 B * v = 2:1x2:struct.(2) % CELL ----- 256 B v[].a = 2:1x1:cell % 1206 196 B - v[].a{} = 2:3x3:double.sparse.complex % CELL ----- 698 B v[].a = 2:1x2:cell % 1206 0 B - v[].a{} = 2:0x0:double % CELL ----- 634 B v[].a{} = 2:1x1:cell % STRUCT --- 574 B v[].a{}{} = 2:1x2:struct.(2) % 1204 2 B - v[].a{}{}[].FA = 2:1x1:char % 1200 4 B - v[].a{}{}[].FA = 2:1x2:char % 1000 200 B - v[].a{}{}[].FB = 2:5x5:double % CELL ----- 0 B v[].a{}{}[].FB = 2:0x0:cell % 1000 0 B - v[].b = 2:0x0:double % CELL ----- 80 B v[].b = 2:1x2:cell % 1000 0 B - v[].b{} = 2:0x0:double % 984 16 B - v[].b{} = 2:1x1:function_handle %} i'm really puzzled... and worried... urs
From: Oleg Komarov on 14 Jul 2010 09:49
"Steven Lord" <slord(a)mathworks.com> wrote in message <i1kdue$1st$1(a)fred.mathworks.com>... > > "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message > news:i1kdan$ko8$1(a)fred.mathworks.com... > > I've been playing with us's vsize when I noticed this strange (?) > > behaviour in the example input: > > > > clear v > > v(1).a{1}=sparse(magic(3)+2i*magic(3)); > > v(2).a{2}={struct('FA',{'a','bb'},'FB',{magic(5),{}})}; > > v(2).b{2}=@(x) sind(x); > > % Size in bytes of v is: 1998 bytes > > At this point, v(1).b is completely empty (nothing in it at all.) However, > when you do this ... > > > v.a; > > v.b; > > > MATLAB has to display _something_ for v(1).b, so it displays (and stores in > v(1).b) an explicit empty matrix, which takes up more memory than "nothing > at all". > > > % now is: 2012 bytes > > > > Can somebody explain me why? > > Read the second sentence in the Description section of this mx-function: > > http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mxcreatestructarray.html > > -- > 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 > Wouldn't it be more cautios to initialize structures with empty inputs instead of pointers (for memory issues)? Oleg |