[Grok-dev] meet the Grok 1.0 release team
Leonardo Rochael Almeida
leorochael at gmail.com
Wed Dec 3 07:46:26 EST 2008
I've read somewhere that for small ints and constant tuples the python
interpreter avoids recreating them (the empty tuple is the best known
example), but this is an internal memory optimization that shouldn't
be relied upon.
On Wed, Dec 3, 2008 at 10:38, Martijn Faassen <faassen at startifact.com> wrote:
> Hey,
>
> On Wed, Dec 3, 2008 at 1:23 PM, Brandon Craig Rhodes
> <brandon at rhodesmill.org> wrote:
>> "Martijn Faassen" <faassen at startifact.com> writes:
>>
>>> I don't think the word 'pestering' is very appropriate.
>>
>> I guess I was having fun. :-) I'll try to sound more official.
>>
>>> To my knowledge tuples are allocated each time the code runs just as
>>> much as lists are, and not only when the program runs first, otherwise
>>> things like this wouldn't work:
>>>
>>> mytuple = a, b
>>
>> It looks to me like the interpreter builds tuples of constants only
>> once:
>>
>>>>> def foo():
>> ... return (1,2,3)
>> ...
>>>>> a = foo()
>>>>> b = foo()
>>>>> id(a)
>> 3084583396L
>>>>> id(b)
>> 3084583396L
>
> Looks like you're right. Interesting, I wonder how it manages to know
> the difference internally.
>
More information about the Grok-dev
mailing list