memory usage

Terry Reedy tjreedy at udel.edu
Sat Dec 6 00:17:03 EST 2003


"Dave" <jaguar4096 at yahoo.com> wrote in message
news:c375aec2.0312052020.6e26239c at posting.google.com...
> Hi,
> I'm writing code which deals with lists of millions to tens of  millions
of
> elements.  It seems to me that python gobbles up memory faster than it
> should in these cases.

Then you might want to use Numerical Python arrays, which wrap C arrays of
native data (ie, 8 bytes per float).

> For example, I start the python interpreter and then execute the
> following code:
>
> >>> f = []
> >>> for i in range(1e7):

You will be happier with xrange(), which was added for this sort of usage.

> ...    f.append(0.1)
>
> In another window on my Linux system I then run top.  The python
> process is now using 155 MB of memory.  Why is python using such a
> large amount of memory, nearly nearly 16 bytes for a float in this
> case?

8 bytes of data, 8 bytes of overhead, I believe.

Terry J. Reedy






More information about the Python-list mailing list