<br><br><div class="gmail_quote">On Tue, Sep 28, 2010 at 6:46 AM, Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
2010/9/27 Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;:<br>
<div class="im">&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Sep 27, 2010 at 12:20 PM, Mariano Martinez Peck &lt;<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Sep 22, 2010 at 12:34 PM, Mariano Martinez Peck &lt;<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Sep 22, 2010 at 12:12 PM, Henrik Johansen &lt;<a href="mailto:henrik.s.johansen@veloxit.no">henrik.s.johansen@veloxit.no</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Sep 22, 2010, at 9:59 40AM, Adrian Lienhard wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; Some notes:<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; - What should be answered for small ints? 1 sizeInMemory --&gt;8. That&#39;s wrong. Shouldn&#39;t this answer 0?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Philosophical question really, imo both 4 (Again, in 32bit images at least) and 0 would be &quot;correct&quot; answers in their own ways. 8 is definitely wrong though :)<br>
&gt;&gt;&gt;&gt; The method comment should probably highlight which definition is used.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; So....what should we consider for SmallInteger ?   4 bytes or 0 bytes?<br>
&gt;<br>
</div>&gt; 0 bytes, obviously.  The only space occupied by a SmallInteger is the space of the slot containing it.  There is no SmallInteger object beyond the slot.<br>
&gt;<br>
<br>
Or from another POV, it&#39;s 4, the size of the slot. But we don&#39;t count<br>
the size of the slots, they are already counted in the containing<br>
object, that&#39;s why it should answer 0.<br></blockquote><div><br><br>Thanks for the answers. I finally let this:<br><br>sizeInMemory<br>    &quot;Answer the number of bytes consumed by this instance including object header.&quot;<br>
    | isCompact headerBytes contentBytes |<br><br>    &quot;SmallInteger occupy 0 bytes since the only space occupied by a SmallInteger is the space of the slot containing it.  There is no SmallInteger object beyond the slot. From another POV, it could be 4, the size of the slot. But we don&#39;t count the size of the slots, they are already counted in the containing object, that&#39;s why it should answer 0.&quot;<br>
    (self isMemberOf: SmallInteger) ifTrue: [^0]. <br><br>     contentBytes := self class instSize * Smalltalk wordSize. &quot;inst vars&quot;<br><br>     self class isVariable ifTrue:[ |bytesPerElement|<br>            bytesPerElement := self class isBytes ifTrue: [1] ifFalse: [4].<br>
            contentBytes := contentBytes + (self basicSize * bytesPerElement)].<br><br>     isCompact := self class indexIfCompact &gt; 0.<br>      headerBytes :=<br>                    contentBytes &gt; 255<br>                        ifTrue: [ 3 * Smalltalk wordSize ] <br>
                        ifFalse: [isCompact ifTrue: [Smalltalk wordSize] ifFalse: [2 * Smalltalk wordSize]].<br>            ^ headerBytes + contentBytes<br><br><br>Now I wonder...maybe instead of doing this it is easier to have a primitive that just calls #internalByteSize: ?<br>
The problem of course is that it needs changes in the vm...<br><br>cheers<br><br>Mariano<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<font color="#888888"><br>
Nicolas<br>
</font><div><div></div><div class="h5"><br>
&gt;&gt;<br>
&gt;&gt; I would like to compute the really used memory.<br>
&gt;&gt;<br>
&gt;&gt; thanks<br>
&gt;&gt;<br>
&gt;&gt; mariano<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; At the beginning I also thought to have 4, instead of 0. The problem is that if you put 4 and you have an object with and instVar that it is a SmallInteger, it will be counted twice, when actually it is only one.<br>

&gt;&gt;&gt; That&#39;s why I thoguht 0 was better, since I want the really occupated memory. On the other hand, if you do &quot;4 sizeInMemory&quot; and see zero, I have to admit it is a litlte confusing.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The problem is that if I do for example:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Class &gt;&gt; spaceForInstances<br>
&gt;&gt;&gt;     | totalSize |<br>
&gt;&gt;&gt;     totalSize := 0.<br>
&gt;&gt;&gt;     self allInstancesDo: [ :inst |<br>
&gt;&gt;&gt;         totalSize := totalSize + inst sizeInMemory.<br>
&gt;&gt;&gt;     ].<br>
&gt;&gt;&gt;     ^ totalSize<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; SmallInteger spaceForInstances  -&gt;&gt;  0<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; So I don&#39;t know...maybe we have to answer 4 instead of 0?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Adrian what do you think?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; - In the line contentBytes := contentBytes + (self basicSize * bytesPerElement), why is contentBytes added because it should be always 0 because self class instSize should return 0 in case of variable classes. Or do I miss something?<br>

&gt;&gt;&gt;&gt; You can have instance variables in variable classes:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ArrayedCollection variableSubclass: #TallyArray<br>
&gt;&gt;&gt;&gt;        instanceVariableNames: &#39;tally&#39;<br>
&gt;&gt;&gt;&gt;        classVariableNames: &#39;&#39;<br>
&gt;&gt;&gt;&gt;        poolDictionaries: &#39;&#39;<br>
&gt;&gt;&gt;&gt;        category: &#39;Collections-Arrayed&#39;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; TallyArray instSize 1<br>
&gt;&gt;&gt;&gt; (TallyArray new: 5) basicSize 5<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Sure, they&#39;re not used very often in Squeak/Pharo since become: is so slow, but there&#39;s no theoretical reason why you can&#39;t for example implement Set as a variable subclass with a tally inst var.<br>

&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; - Please remove the inline comment &quot;inst vars&quot;; if a comment is needed it should go into the main comment.<br>
&gt;&gt;&gt;&gt; I agree, should be self-explanatory.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Cheers,<br>
&gt;&gt;&gt;&gt; Henry<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; Pharo-project mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
&gt;&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;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>