- E04 - Leadership! Google, Guido van Rossum, PSF

Duncan Booth duncan.booth at invalid.invalid
Tue Jan 3 15:10:28 EST 2006


Alex Martelli wrote:

> Duncan Booth <duncan.booth at invalid.invalid> wrote:
>> That's a horrible suggestion (using id's, not the bit about separate 
>> namespaces). If you use the id then attributes will persist beyond
>> the lifetime of the object and may suddenly reappear on other
>> unrelated objects later.
> 
> The second sentence is true, but does not imply the first: just add a
> strong reference to the object you're imposing extra attributes on
> (e.g., pile such objects into an auxiliary list).
> 
Except that would lead to fairly massive memory leaks, so isn't really
of practical use. I guess you could combine an auxiliary list with a
periodic scan of the list releasing those objects which are referenced
only from the list, which would reduce the problem to objects
participating in cycles. Combine that with the weak reference approach
wherever it works and you might be able to cover most situations. 

> 
>> With the above code what would 'puts
>> someexpressionresultingin1234.meta' output? i.e. is the attribute
>> being set on all integers with the value 1234, or just on a specific
>> instance of an integer. 
> 
> Good question, presumably answerable with a small Ruby test (which
> however I have no time to perform right now;-).

Hans Nowak seems to have partly answered that. It looks as though the id
of a Ruby integer is one more than twice the integer's value so I guess
that ruby packs the integer value in place of the object reference. A
quick search reveals: 

> A Fixnum holds Integer values that can be represented in a native
> machine word (minus 1 bit). If any operation on a Fixnum exceeds this
> range, the value is automatically converted to a Bignum. 
> 
> Fixnum objects have immediate value. This means that when they are
> assigned or passed as parameters, the actual object is passed, rather
> than a reference to that object. Assignment does not alias Fixnum
> objects. There is effectively only one Fixnum object instance for any
> given integer value, so, for example, you cannot add a singleton
> method to a Fixnum. 

So it looks like the Ruby example will work as observed for integers which 
fit in one bit smaller than a machine word and then work differently for 
larger integers.





More information about the Python-list mailing list