Ok, the problem was that I was doing:<br><br>usedMemory := usedMemory + self internalByteSize: oop.<br><br>that didn't work and always answered me the same number.<br><br>Now, I had to do this:<br><br>usedMemory := usedMemory + (self internalByteSize: oop). <br>
<br>I don't understand why. <br><br>Thanks<br><br>Mariano<br><br><div class="gmail_quote">On Thu, Apr 29, 2010 at 3:22 PM, Mariano Martinez Peck <span dir="ltr"><<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>></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><br><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<br></div>
It's close but not entirely correct. The computation needs to include the extra header word for "large" instances (> 255 bytes). Squeak has three possible header sizes:<br>
<br>
1 header word - used by compact classes<br>
2 header words - used by regular classes<br>
3 header words - used by "large" instances<br>
<br>
BTW, SpaceTally>>spaceForInstancesOf:withInstanceCount: has the correct computation (except for 64 bit :-)<div><br></div></blockquote></div><div><br>Ok, perfect. Thanks :)<br><br> </div><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Is there a way to know this<br>
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>
</blockquote>
<br></div>
It's easy to do in the VM, just use this:<br>
<br>
primitiveByteSize<br>
"Answers the number of bytes the receiver occupies"<br>
<br>
| nbytes|<br>
self export: true.<br>
oop := self popStack.<br>
nbytes := (self sizeBitsOf: oop) + (self extraHeaderBytes: oop).<br>
self pushInteger: nbytes.<br>
<br>
</blockquote></div><div><br><br>I tried this and seems to work ok. I don't really need a primitive but an internal method that is called by a primitive. So, I did something like this:<br><br>internalByteSize: anOop<div class="im">
<br> "Answers the number of bytes the receiver occupies"<br>
| nbytes|<br></div> self inline: true.<br> nbytes := (self sizeBitsOf: anOop) + (self extraHeaderBytes: anOop).<br> ^ nbytes.<br><br><br><br>and then I call it like this for example:<br><br>oop := self firstAccessibleObject.<br>
[oop = nil] whileFalse: [<br> (self isIntegerObject: oop)<br> ifFalse: [ <br> size := self internalByteSize: oop. <br> ......]<br> oop := self accessibleObjectAfter: oop.<br>
].<br><br> <br>but internalByteSize ALWAYS return me the same value...do you know what can be wrong ?<br><br>Thanks in advance<br><br>Mariano<br><br></div></div><br>
</blockquote></div><br>