Hi folks. Sorry for the cross post this time, but I guess it is worth.<br><br>In Pharo we were trying to get a way to know the amount of memory (bytes) that an objects is occupying in RAM memory. <br><br>For such purpose, Adrian posposed the following method:<br>
<br>Object>>sizeInMemory<br>
"Returns the number of bytes used by this object in memory
(including its header)"<br>
<br>
| headerSize instanceSize |<br>
headerSize := (self class indexIfCompact > 0 ifTrue: [ 4 ]
ifFalse: [ 8 ]).<br>
instanceSize := (self class isVariable<br>
ifFalse: [ self class instSize * Smalltalk wordSize ]<br>
ifTrue: [ (self basicSize * (self class isBytes<br>
ifTrue: [ 1 ] ifFalse: [ Smalltalk wordSize ]))
]).<br>
^ headerSize + instanceSize<br><br><br><br>Do you think this is correct for all cases? Is there a way to know this 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>
<br>Thanks<br><br>Mariano<br><br><br><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Adrian Lienhard</b> <span dir="ltr"><<a href="mailto:adi@netstyle.ch">adi@netstyle.ch</a>></span><br>
Date: Tue, Apr 27, 2010 at 1:19 PM<br>Subject: Re: [Pharo-project] is it possible to know the memory occupation (bytes) of an object?<br>To: <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<br><br>Its a simple method in Object:<br>
<br>
Object>>sizeInMemory<br>
"Returns the number of bytes used by this object in memory (including its header)"<br>
<br>
| headerSize instanceSize |<br>
headerSize := (self class indexIfCompact > 0 ifTrue: [ 4 ] ifFalse: [ 8 ]).<br>
instanceSize := (self class isVariable<br>
ifFalse: [ self class instSize * Smalltalk wordSize ]<br>
ifTrue: [ (self basicSize * (self class isBytes<br>
ifTrue: [ 1 ] ifFalse: [ Smalltalk wordSize ])) ]).<br>
^ headerSize + instanceSize<br>
<br>
Please also note the other mail I sent to this thread.<br>
<font color="#888888"><br>
Adrian<br>
</font><div><div></div><div class="h5"><br>
On Apr 27, 2010, at 13:16 , Mariano Martinez Peck wrote:<br>
<br>
> On Tue, Apr 27, 2010 at 12:45 PM, Adrian Lienhard <<a href="mailto:adi@netstyle.ch">adi@netstyle.ch</a>> wrote:<br>
><br>
>> I once sent some code to the mailing list (search for thread named "Size of<br>
>> objects").<br>
><br>
><br>
> Thanks Adrian...I couldn't find it. Can you forward it to me please? or<br>
> just send me the code...<br>
><br>
><br>
>> We should add this to the image. I think I named it #sizeInMemory.<br>
>><br>
>><br>
> There are only changes to the image side ? or the vm also ?<br>
><br>
> Thanks<br>
><br>
> Mariano<br>
><br>
><br>
><br>
>> Adrian<br>
>><br>
>> On Apr 27, 2010, at 12:03 , Mariano Martinez Peck wrote:<br>
>><br>
>>> Hi. I don't know if "memory occupation" is the better name. I just want<br>
>> to<br>
>>> know the amount of memory that an object is occupying in RAM. I mean, the<br>
>>> amount of bytes.<br>
>>><br>
>>> Is this possible ? if true, how ? I would like to do it from both<br>
>> sides:<br>
>>> image and VM.<br>
>>><br>
>>> I checked both but I didn't find anything.<br>
>>><br>
>>> Thanks in advance<br>
>>><br>
>>> Mariano<br>
>>> _______________________________________________<br>
>>> Pharo-project mailing list<br>
>>> <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
>>> <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>
>><br>
>><br>
>> _______________________________________________<br>
>> Pharo-project mailing list<br>
>> <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
>> <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>
>><br>
> _______________________________________________<br>
> Pharo-project mailing list<br>
> <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
> <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>
<br>
<br>
_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<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>
</div></div></div><br>