Issues creating instance of SmallInteger

John M McIntosh johnmci at smalltalkconsulting.com
Fri May 12 17:19:37 UTC 2006


Mmm let me clarify some things.

First object point to other objects via an object reference, one  
shouldn't call them pointers because
they technically aren't true pointers from the "C" sense of the word.  
For example earlier smalltalk used an
index into an object table, and why would you need more than 64K of  
objects in your image anyway?

When object references were thought up at some point someone had the  
clever idea if I'm holding onto
this data to refer to another object, why can't that data be the  
object. Thus the concept of an immediate object type
was born. In Squeak we use 2 bits of the 32 in 32bit Squeak, 1 bit  
for a tag for the GC logic, and the other bit to signify if this  
object is a
SmallInteger.

xxxxxxxx00 -> object reference (tag bit not set; divisible by four)
xxxxxxxx10 -> Unused (tag bit not set; but not a valid pointer)
xxxxxxxx01 -> SmallInteger (tag bit set)
xxxxxxxx11 -> SmallInteger (tag bit set)

That of course gives us a range of +_ 1 billionish
(0 - (2 raisedTo: 30)) to ((2 raisedTo: 30) - 1)

I'll note other Smalltalk might have different immediate data types  
and 64bit Smalltalks usually have lots more
immediate types, such as single precision float, small doubles, and  
character.

Lastly, I'm afraid we do create many copies of 42 since people do  
alter them. However there is a grain of truth in your comment since  
we don't create many copies of $A  If you look at the Class Character  
you'll see: "I represent a character by storing its associated  
Unicode. The first 256 characters are created uniquely, so that all  
instances of latin1 characters ($R, for example) are identical." So  
Characters are immutable.

On 12-May-06, at 9:11 AM, Damien Pollet wrote:

> On 5/12/06, Michel Calonne <Michel.Calonne at etu.univ-savoie.fr> wrote:
>> (Smalltalk at: #AClassName) new
>> The problem is that, when trying to create an instance of  
>> SmallInteger, it raises an error :
>> "SmallIntegers can only be created by performing arithmetic"...
>
> That's because integers are pure values, they are immutable. It
> wouldn't make sense to create several copies of 42...
>

--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===




More information about the Squeak-dev mailing list