Hi Marcus, On Thu, Oct 26, 2017 at 1:09 AM, Marcus Denker <[email protected]> wrote:
> > > On 26 Oct 2017, at 10:05, Denis Kudriashov <[email protected]> wrote: > > Hi. > > Question from discord, why: > > 2017 sizeInMemory = 0 > > ? > > Looks like a bug, but maybe there is some reason for this. > > > #sizeInMemory only takes into account object header size and the size of > the object > itself. > sizeInMemory is also ignorant of details such as the padding of objects to 64-bits in both 32-bit and 64-bit Spur, the overflow header when there are more than 254 slots, etc. siseInMemory should really be implemented like this: Object>>sizeInMemory ^self class isVariable ifTrue: [self class byteSizeOfInstanceOfSize: self basicSize] ifFalse: [self class byteSizeOfInstance] where the subsidiary definitions are Behavior>>byteSizeOfInstance "Answer the total memory size of an instance of the receiver." <primitive: 181 error: ec> self isVariable ifTrue: [^self byteSizeOfInstanceOfSize: 0]. self isImmediateClass ifTrue: [^0]. self primitiveFailed byteSizeOfInstanceOfSize: basicSize "Answer the total memory size of an instance of the receiver with the given number of indexable instance variables." <primitive: 181 error: ec> self isVariable ifTrue: "If the primitive overflowed answer a close approximation" [(basicSize isInteger and: [basicSize >= 16r1000000]) ifTrue: [^2 * (self byteSizeOfInstanceOfSize: basicSize + 1 // 2) - (self byteSizeOfInstanceOfSize: 0)]] ifFalse: [basicSize = 0 ifTrue: [^self byteSizeOfInstance]]. self primitiveFailed > A small-integer is encoded in the pointer, so it has no size in itself, > only the object > pointing to it needs space for the pointer, just like for normal object. > As are Characters, and in 64-bits the single-precision range of the double-precision floats: { SmallInteger maxVal sizeInMemory. (SmallInteger maxVal + 1) sizeInMemory. 1.0e38 sizeInMemory. 1.0e39 sizeInMemory. $a sizeInMemory } in 64 bit is #(0 16 0 16 0) in 32 bit is #(0 16 16 16 0) The overflow header is revealed by (251 to: 258) collect: [:n| (Array new: n) sizeInMemory] in 64 bit is #(2016 2024 2032 2040 2056 2064 2072 2080) in 32 bit is #(1016 1016 1024 1024 1040 1040 1048 1048) _,,,^..^,,,_ best, Eliot
