Re: memory usage, temporary and otherwise

2010-03-04 Thread Steve Holden
Duncan Booth wrote: > mk wrote: > >> Hm, apparently Python didn't spot that 'spam'*10 in a's values is really >> the same string, right? > > If you want it to spot that then give it a hint that it should be looking > for identical strings: > > >>> a={} > >>> for i in range(1000): > ...

Re: memory usage, temporary and otherwise

2010-03-04 Thread Terry Reedy
On 3/4/2010 6:56 AM, mk wrote: Bruno Desthuilliers wrote: Huh? I was under impression that some time after 2.0 range was made to work "under the covers" like xrange when used in a loop? Or is it 3.0 that does that? 3.0. -- http://mail.python.org/mailman/listinfo/python-list

Re: memory usage, temporary and otherwise

2010-03-04 Thread lbolla
On Mar 4, 12:24 pm, Duncan Booth wrote: > >  >>> a={} >  >>> for i in range(1000): > ...     a[i]=intern('spam'*10) > "intern": another name borrowed from Lisp? -- http://mail.python.org/mailman/listinfo/python-list

Re: memory usage, temporary and otherwise

2010-03-04 Thread Duncan Booth
mk wrote: > Hm, apparently Python didn't spot that 'spam'*10 in a's values is really > the same string, right? If you want it to spot that then give it a hint that it should be looking for identical strings: >>> a={} >>> for i in range(1000): ... a[i]=intern('spam'*10) should reduc

Re: memory usage, temporary and otherwise

2010-03-04 Thread mk
Bruno Desthuilliers wrote: mk a écrit : Obviously, don't try this on low-memory machine: a={} for i in range(1000): Note that in Python 2, this will build a list of 1000 int objects. You may want to use xrange instead... Huh? I was under impression that some time after 2.0 range w

Re: memory usage, temporary and otherwise

2010-03-03 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : > mk a écrit : (snip) >> So sys.getsizeof returns some 200MB for this dictionary. But according >> to top RSS of the python process is 300MB. ps auxw says the same thing >> (more or less). >> >> Why the 50% overhead? Oh, and yes - the interpreter itself, the builtins

Re: memory usage, temporary and otherwise

2010-03-03 Thread Bruno Desthuilliers
mk a écrit : > > Obviously, don't try this on low-memory machine: > a={} for i in range(1000): Note that in Python 2, this will build a list of 1000 int objects. You may want to use xrange instead... > ... a[i]='spam'*10 > ... import sys sys.getsizeof(a) > 201326

memory usage, temporary and otherwise

2010-03-03 Thread mk
Obviously, don't try this on low-memory machine: >>> a={} >>> for i in range(1000): ... a[i]='spam'*10 ... >>> import sys >>> sys.getsizeof(a) 201326728 >>> id(a[1]) 3085643936L >>> id(a[100]) 3085713568L >>> ids={} >>> for i in range(len(a)): ... ids[id(a[i])]=True ... >>> len(ids.