I am out of trial and error again Lists

Chris Angelico rosuav at gmail.com
Thu Oct 23 23:32:18 EDT 2014


On Fri, Oct 24, 2014 at 2:14 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> Example that works 'instantly' in 3.x, but would be slightly insane in 2.x,
> even if you have enough memory for it to work on a 64 bit build.
>
>>>> r =range(0, 1000000000000000, 999937)
>>>> 3428761974385 in r
> False
>>>> 3428761974386 in r
> True

That's over a billion entries. The array of pointers alone would be
roughly 4GB on a 32-bit build, so there's no way that'll ever fit...
on a 64-bit build, that'll take up 8GBish for the list, plus probably
24 bytes minimum per integer, so even if there's absolutely no heap
overhead, you're still looking at 32GB to store that list. Yeeeouch. I
think we can drop the "slightly" from your description! For
comparison, a 64-bit Python 3 says:

>>> sys.getsizeof(range(0, 1000000000000000, 999937))
48

Thanks, much nicer.

ChrisA



More information about the Python-list mailing list