[Squeak] How to get the size of any object

NISHIHARA Satoshi nishis at urban.ne.jp
Thu Sep 17 14:12:01 UTC 1998


I'm porting some Metrics tool for VW to Squeak.
And I can't decide the code is right or wrong...
(or in the first place, the concept is wrong ;-P)

My code is...

"begin"
byteSizeOfObject: anObject 
    | bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize
byteSize |
    bytesInOTE := 12.       "ObjectMemory current bytesPerOTE."
    bytesInOOP := 4.        "ObjectMemory current bytesPerOOP."
    aClass := anObject class.
    aClass isPointers
        ifTrue: 
            [instVarFieldSize := aClass instSize * bytesInOOP.
            aClass isVariable
                ifTrue: 
                    [aClass isWords 
                        ifTrue: 
                            [indexableFieldSize := anObject basicSize *
bytesInOOP / 2]
                        ifFalse: 
                            [indexableFieldSize := anObject basicSize *
bytesInOOP]]
                ifFalse: [indexableFieldSize := 0]]
        ifFalse: 
            [instVarFieldSize := 0.
            aClass isVariable
                ifTrue: 
                    [aClass isWords 
                        ifTrue: 
                            [indexableFieldSize := anObject basicSize +
(bytesInOOP / 2 - 1) bitAnd: bytesInOOP / 2 negated]
                        ifFalse: 
                            [indexableFieldSize := anObject basicSize +
(bytesInOOP - 1) bitAnd: bytesInOOP negated]]
                ifFalse: 
                    [indexableFieldSize := 0.
                    "exists?"
                    aClass format = 0 ifTrue: [bytesInOTE := 0]]].
    byteSize := bytesInOTE + instVarFieldSize + indexableFieldSize.
    ^byteSize
"begin"


Original VW code as below
"begin"
byteSizeOfObject: anObject 
    | bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize
byteSize |
    bytesInOTE := ObjectMemory current bytesPerOTE.
    bytesInOOP := ObjectMemory current bytesPerOOP.
    aClass := anObject class.
    aClass isPointers
        ifTrue: 
            [instVarFieldSize := aClass instSize * bytesInOOP.
            aClass isVariable
                ifTrue: [indexableFieldSize := anObject basicSize * bytesInOOP]
                ifFalse: [indexableFieldSize := 0]]
        ifFalse: 
            [instVarFieldSize := 0.
            aClass isVariable
                ifTrue: [indexableFieldSize := anObject basicSize +
(bytesInOOP - 1) bitAnd: bytesInOOP negated]
                ifFalse: 
                    [indexableFieldSize := 0.
                    aClass hasImmediateInstances ifTrue: [bytesInOTE := 0]]].
    byteSize := bytesInOTE + instVarFieldSize + indexableFieldSize.
    ^byteSize
"end"

-p.s.-

2.2 beta is fine!
(But MVC will survive? ;-))

regards
-------------------------------------------
$B@>86Ao;N(B (NISHIHARA Satoshi)
e-mail: nishis at urban.ne.jp
      : tcc00164 at nifty.ne.jp
URL: http://www.urban.ne.jp/home/nishis/
-------------------------------------------





More information about the Squeak-dev mailing list