Surprise using the 'is' operator

tobiah toby at tobiah.org
Wed Sep 27 12:24:40 EDT 2006


>> Suppose I fill an list with 100 million random integers in the range
>> of 1 - 65535.  Wouldn't I save much memory if all of the ocurrances
>> of '12345' pointed to the same integer object?  Why should more be made,
>> when they all do the same thing, and are not subject to change?
> 
> Because for typical usage of integers (which doesn't include your example),
> it is more expensive to check if there's already an integer with that 
> specific
> value out there than to create a new one.
> 
> 
> Georg

I see.  I assume then, that the lookup performance hit is acceptable
as a trade off against memory usage for the quite commonly used range
of (-5, 257).  Is that the idea?

Thanks,

Tobiah

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list