Surprise using the 'is' operator
Steve Holden
steve at holdenweb.com
Wed Sep 27 12:58:51 EDT 2006
tobiah wrote:
> Simon Brunning wrote:
>
>>On 9/27/06, tobiah <toby at tobiah.org> wrote:
>>
>>>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?
>>
>>If you were to drop that list, then to generate another large list of
>>integers, you'd want to re-use the memory from the first lot, wouldn't
>>you?
>>
>>(BTW, AFAIK, integers are kept seperate from other objects
>>memory-wise, so memory used for integers won'tr be re-used for other
>>object types. but memory used for integers can be re-used for *other*
>>integers. I think.)
>>
>
>
> I'm confused now, but yes, I would want to reuse the memory for
> the other integers. That's why I understand why I get the same
> id back for small integers, but why limit that to (-5, 257)?
>
> Thanks,
>
> Toby
>
It's what's called an "implementation detail". Don't even worry about it
until you need to shave every microsecond off your program's execution
time, as reliance on such details reduces portability.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list