question on string object handling in Python 2.7.8

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 24 11:39:31 EST 2014


On Wed, Dec 24, 2014 at 4:22 AM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:
> What happens here is that you time a piece of code to:
>
> - Build a large list containing 100 million individual int objects. Each
int
> object has to be allocated at run time, as does the list. Each int object
> is about 12 bytes in size.

Note to the OP: since you're using Python 2 you would do better to loop
over an xrange object instead of a range. xrange produces an iterator over
the desired range without needing to construct a single list containing all
of them. They would all still need to be allocated, but not all at once,
and memory could be reused.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141224/a199b1b3/attachment.html>


More information about the Python-list mailing list