Hi Frédéric

Nice to see you on the Pharo mailing list!

Just the other day I needed this too and I implemented the following method:

Object>>sizeInMemory
"Returns the number of bytes used by this object in memory (including its header)"
        
        | headerSize instanceSize |
headerSize := (self class indexIfCompact > 0 ifTrue: [ 4 ] ifFalse: [ 8 ]).
        instanceSize := (self class isVariable
                ifFalse: [ self class instSize * Smalltalk wordSize ]
                ifTrue: [ (self basicSize * (self class isBytes
                        ifTrue: [ 1 ] ifFalse: [ Smalltalk wordSize ])) ]).
        ^ headerSize + instanceSize


BTW, I think that would be a meaningful addition. Could somebody quickly check the method to verify that I didn't do any miscalculation?

Cheers,
Adrian

On Oct 21, 2008, at 17:58 , Frederic Pluquet wrote:

Hello,

For an experimentation, I need to know the size in bytes of any object. Is there a way to obtain this information in Pharo ?

Fréd

--
Frédéric Pluquet
Université Libre de Bruxelles (ULB)
Assistant
http://www.ulb.ac.be/di/fpluquet
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to