Status: New
Owner: ----
New issue 4543 by
[hidden email]: Wrong calculated size of objects
in memory
http://code.google.com/p/pharo/issues/detail?id=4543Pharo image: Pharo
Pharo core version: Pharo1.3a Latest update: #13204
Virtual machine used: custom
Steps to reproduce:
1. print this: (ByteArray new: 252) sizeInMemory
2. it says 260, but the real size is 264 (252 for bytes, 4 for base header,
8 for extra header).
The problem is really really subtle. The object carries a 2 words extra
header if its size is bigger than 255 (because otherwise size won't fit in
the 8 bit size field). But which size? The response is that the size is the
amount of bytes including the base header but not the extra header. Because
of that, the code should add the size of the base header before checking if
size > 255. This bug only affects objects whose base size is less than 256,
but that after adding the base header go over 255.
Here is a proposed implementation that fixes the problem:
sizeInMemory
"Answer the number of bytes consumed by this instance including object
header."
| contentBytes |
contentBytes := Smalltalk wordSize. "base header"
contentBytes := contentBytes + (self class instSize * Smalltalk
wordSize). "instance vars"
self class isVariable ifTrue:[ | bytesPerElement | "indexed elements"
bytesPerElement := self class isBytes ifTrue: [1] ifFalse: [4].
contentBytes := contentBytes + (self basicSize * bytesPerElement)
].
contentBytes > 255 ifTrue: [ contentBytes := contentBytes + (2 *
Smalltalk wordSize) ]
ifFalse: [ self class indexIfCompact > 0
ifFalse: [ contentBytes := contentBytes + Smalltalk wordSize]
].
^contentBytes
_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker