Hi folks. Sorry for the cross post this time, but I guess it is worth.<br><br>In Pharo we were trying to get a way to know the amount of memory (bytes) that an objects is occupying in RAM memory. <br><br>For such purpose, Adrian posposed the following method:<br>
<br>Object&gt;&gt;sizeInMemory<br>
        &quot;Returns the number of bytes used by this object in memory 
(including its header)&quot;<br>
<br>
        | headerSize instanceSize |<br>
        headerSize := (self class indexIfCompact &gt; 0 ifTrue: [ 4 ] 
ifFalse: [ 8 ]).<br>
        instanceSize := (self class isVariable<br>
                ifFalse: [ self class instSize * Smalltalk wordSize ]<br>
                ifTrue: [ (self basicSize * (self class isBytes<br>
                        ifTrue: [ 1 ] ifFalse: [ Smalltalk wordSize ])) 
]).<br>
        ^ headerSize + instanceSize<br><br><br><br>Do you think this is correct for all cases?  Is there a way to know this but from the VM side also ? how ?<br>I really need it from the VM side :(  but I have no idea how to do it.<br>
<br>Thanks<br><br>Mariano<br><br><br><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Adrian Lienhard</b> <span dir="ltr">&lt;<a href="mailto:adi@netstyle.ch">adi@netstyle.ch</a>&gt;</span><br>
Date: Tue, Apr 27, 2010 at 1:19 PM<br>Subject: Re: [Pharo-project] is it possible to know the memory occupation (bytes) of an object?<br>To: <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<br><br>Its a simple method in Object:<br>
<br>
Object&gt;&gt;sizeInMemory<br>
        &quot;Returns the number of bytes used by this object in memory (including its header)&quot;<br>
<br>
        | headerSize instanceSize |<br>
        headerSize := (self class indexIfCompact &gt; 0 ifTrue: [ 4 ] ifFalse: [ 8 ]).<br>
        instanceSize := (self class isVariable<br>
                ifFalse: [ self class instSize * Smalltalk wordSize ]<br>
                ifTrue: [ (self basicSize * (self class isBytes<br>
                        ifTrue: [ 1 ] ifFalse: [ Smalltalk wordSize ])) ]).<br>
        ^ headerSize + instanceSize<br>
<br>
Please also note the other mail I sent to this thread.<br>
<font color="#888888"><br>
Adrian<br>
</font><div><div></div><div class="h5"><br>
On Apr 27, 2010, at 13:16 , Mariano Martinez Peck wrote:<br>
<br>
&gt; On Tue, Apr 27, 2010 at 12:45 PM, Adrian Lienhard &lt;<a href="mailto:adi@netstyle.ch">adi@netstyle.ch</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; I once sent some code to the mailing list (search for thread named &quot;Size of<br>
&gt;&gt; objects&quot;).<br>
&gt;<br>
&gt;<br>
&gt; Thanks Adrian...I couldn&#39;t find it. Can you forward it to me please?  or<br>
&gt; just send me the code...<br>
&gt;<br>
&gt;<br>
&gt;&gt; We should add this to the image. I think I named it #sizeInMemory.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt; There are only changes to the image side ?  or the vm also ?<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt; Mariano<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;&gt; Adrian<br>
&gt;&gt;<br>
&gt;&gt; On Apr 27, 2010, at 12:03 , Mariano Martinez Peck wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; Hi. I don&#39;t know if &quot;memory occupation&quot; is the better name. I just want<br>
&gt;&gt; to<br>
&gt;&gt;&gt; know the amount of memory that an object is occupying in RAM. I mean, the<br>
&gt;&gt;&gt; amount of bytes.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Is this possible ? if true, how ?   I would like to do it from both<br>
&gt;&gt; sides:<br>
&gt;&gt;&gt; image and VM.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I checked both but I didn&#39;t find anything.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks in advance<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Mariano<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Pharo-project mailing list<br>
&gt;&gt;&gt; <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
&gt;&gt;&gt; <a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Pharo-project mailing list<br>
&gt;&gt; <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
&gt;&gt; <a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br>
&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; Pharo-project mailing list<br>
&gt; <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
&gt; <a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br>
<br>
<br>
_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br>
</div></div></div><br>