Re: Mutable numbers

2006-02-21 Thread Magnus Lycka
Suresh Jeevanandam wrote: > # I am new to python. [...] > In any application most of the operation is numerical. So, i think, we > should get a good speed advantage with the availability of mutable > numbers. What do you think ? If you are new to Python, I think you should try to learn how to us

Re: Mutable numbers

2006-02-21 Thread skip
Rocco> def f(): Rocco> a = 12100 Rocco> b = 12100 Rocco> c = 121*100 Rocco> print a is b Rocco> print a is c That the object with value 12100 is referenced by both a and b is a side effect of byte code compilation by CPython not an inherent property

Re: Mutable numbers

2006-02-21 Thread Rocco Moretti
Steve Holden wrote: > fraca7 wrote: > >> The memory allocation for integers is optimized. 'Small' integers >> (between -5 and 100 IIRC) are allocated once and reused. The memory >> for larger integers is allocated once and reused whenever possible, so >> the malloc() overhead is negligible. >

Re: Mutable numbers

2006-02-21 Thread fraca7
fraca7 a écrit : > Steve Holden a écrit : > >> [Thinks: or maybe fraca7 just meant that integers will be garbage >> collected when there are no more references to them]. > > Actually I meant that the memory is reused, but the same integer won't > always have the same address. And of course thi

Re: Mutable numbers

2006-02-21 Thread fraca7
Steve Holden a écrit : > [Thinks: or maybe fraca7 just meant that integers will be garbage > collected when there are no more references to them]. Actually I meant that the memory is reused, but the same integer won't always have the same address. I guess that in your example, the '121' is ass

Re: Mutable numbers

2006-02-21 Thread Dave Hansen
On Tue, 21 Feb 2006 12:44:52 +0530 in comp.lang.python, Suresh Jeevanandam <[EMAIL PROTECTED]> wrote: ># I am new to python. > >In python all numbers are immutable. This means there is one object ( a >region in the memory ) created every time we do an numeric operation. I >hope there should have

Re: Mutable numbers

2006-02-21 Thread Fredrik Lundh
Steve Holden wrote: > > The memory allocation for integers is optimized. 'Small' integers > > (between -5 and 100 IIRC) are allocated once and reused. The memory for > > larger integers is allocated once and reused whenever possible, so the > > malloc() overhead is negligible. > > The first bit's

Re: Mutable numbers

2006-02-21 Thread Fredrik Lundh
Steve Holden wrote: > > The memory allocation for integers is optimized. 'Small' integers > > (between -5 and 100 IIRC) are allocated once and reused. The memory for > > larger integers is allocated once and reused whenever possible, so the > > malloc() overhead is negligible. > > The first bit's

Re: Mutable numbers

2006-02-21 Thread Steve Holden
fraca7 wrote: > Suresh Jeevanandam a écrit : > >># I am new to python. >> >>In python all numbers are immutable. This means there is one object ( a >>region in the memory ) created every time we do an numeric operation. I >>hope there should have been some good reasons why it was designed this w

Re: Mutable numbers

2006-02-21 Thread Steve Holden
fraca7 wrote: > Suresh Jeevanandam a écrit : > >># I am new to python. >> >>In python all numbers are immutable. This means there is one object ( a >>region in the memory ) created every time we do an numeric operation. I >>hope there should have been some good reasons why it was designed this w

Re: Mutable numbers

2006-02-21 Thread fraca7
Suresh Jeevanandam a écrit : > # I am new to python. > > In python all numbers are immutable. This means there is one object ( a > region in the memory ) created every time we do an numeric operation. I > hope there should have been some good reasons why it was designed this way. The memory all

Re: Mutable numbers

2006-02-21 Thread Giovanni Bajo
Suresh Jeevanandam wrote: > In python all numbers are immutable. True. > This means there is one object ( > a region in the memory ) created every time we do an numeric > operation. False. Memory regions can be pooled in a way that "allocation" is a O(1) operation. > I hope there should have b

Re: Mutable numbers

2006-02-20 Thread Erik Max Francis
Suresh Jeevanandam wrote: > But why not have mutable numbers also in the language. The short answer I'd give is probably that this is so easy to do with a user-defined class that it's never been all that pressing. > In any application most of the operation is numerical. So, i think, we > shoul