[Vm-dev] Fwd: [Pharo-project] is it possible to know the memory occupation (bytes) of an object?

Mariano Martinez Peck marianopeck at gmail.com
Wed Apr 28 18:00:24 UTC 2010


Hi folks. Sorry for the cross post this time, but I guess it is worth.

In Pharo we were trying to get a way to know the amount of memory (bytes)
that an objects is occupying in RAM memory.

For such purpose, Adrian posposed 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



Do you think this is correct for all cases?  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.

Thanks

Mariano




---------- Forwarded message ----------
From: Adrian Lienhard <adi at netstyle.ch>
Date: Tue, Apr 27, 2010 at 1:19 PM
Subject: Re: [Pharo-project] is it possible to know the memory occupation
(bytes) of an object?
To: Pharo-project at lists.gforge.inria.fr


Its a simple method in Object:

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

Please also note the other mail I sent to this thread.

Adrian

On Apr 27, 2010, at 13:16 , Mariano Martinez Peck wrote:

> On Tue, Apr 27, 2010 at 12:45 PM, Adrian Lienhard <adi at netstyle.ch> wrote:
>
>> I once sent some code to the mailing list (search for thread named "Size
of
>> objects").
>
>
> Thanks Adrian...I couldn't find it. Can you forward it to me please?  or
> just send me the code...
>
>
>> We should add this to the image. I think I named it #sizeInMemory.
>>
>>
> There are only changes to the image side ?  or the vm also ?
>
> Thanks
>
> Mariano
>
>
>
>> Adrian
>>
>> On Apr 27, 2010, at 12:03 , Mariano Martinez Peck wrote:
>>
>>> Hi. I don't know if "memory occupation" is the better name. I just want
>> to
>>> know the amount of memory that an object is occupying in RAM. I mean,
the
>>> amount of bytes.
>>>
>>> Is this possible ? if true, how ?   I would like to do it from both
>> sides:
>>> image and VM.
>>>
>>> I checked both but I didn't find anything.
>>>
>>> Thanks in advance
>>>
>>> Mariano
>>> _______________________________________________
>>> Pharo-project mailing list
>>> Pharo-project at lists.gforge.inria.fr
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> Pharo-project at lists.gforge.inria.fr
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
Pharo-project at lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20100428/277211cd/attachment-0001.htm


More information about the Vm-dev mailing list