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:
1 header word - used by compact classes 2 header words - used by regular classes 3 header words - used by "large" instances
BTW, SpaceTally>>spaceForInstancesOf:withInstanceCount: has the correct computation (except for 64 bit :-)
Ok, perfect. Thanks :)
Is there a way to know this
but from the VM side also ? how ? I really need it from the VM side :( but I have no idea how to do it.
It's easy to do in the VM, just use this:
primitiveByteSize "Answers the number of bytes the receiver occupies"
| nbytes| self export: true. oop := self popStack. nbytes := (self sizeBitsOf: oop) + (self extraHeaderBytes: oop). self pushInteger: nbytes.
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: internalByteSize: anOop "Answers the number of bytes the receiver occupies" | nbytes| self inline: true. nbytes := (self sizeBitsOf: anOop) + (self extraHeaderBytes: anOop). ^ nbytes. and then I call it like this for example: oop := self firstAccessibleObject. [oop = nil] whileFalse: [ (self isIntegerObject: oop) ifFalse: [ size := self internalByteSize: oop. ......] oop := self accessibleObjectAfter: oop. ]. but internalByteSize ALWAYS return me the same value...do you know what can be wrong ? Thanks in advance Mariano