Memory problem

John Machin sjmachin at lexicon.net
Mon Aug 14 17:28:58 EDT 2006


Yi Xing wrote:
> I tried the following code:
>
> >>> i=0
> >>> n=2600*2600*30
> >>> a=array.array("f")
> >>> while (i<=n):
> ..     i=i+1
> ..     a.append(float(i))

Not a good idea. The array has to be resized, which may mean that a
realloc won't work because of fragmentation, you're out of luck because
plan B is to malloc another chunk, but that's likely to fail as well.
> ..
> Traceback (most recent call last):
>   File "<stdin>", line 3, in ?
> MemoryError
>
> to see the size of the array at the time of memory error:
> >>>len(a)
> 8539248.

Incredible. That's only 34 MB. What is the size of your paging file?
What memory guzzlers were you running at the same time? What was the
Task Manager "Performance" pane showing while your test was running?
What version of Python?

FWIW I got up to len(a) == 122998164 (that's 14 times what you got) on
a machine with  only 1GB of memory and a 1523MB paging file, with
Firefox & ZoneAlarm running (the pagefile was showing approx 300MB in
use at the start of the test).

> I use Windows XP x64 with 4GB RAM.

Maybe there's a memory allocation problem with the 64-bit version.
Maybe MS just dropped in the old Win95 memory allocator that the timbot
used to fulminate about :-(

Cheers,
John




More information about the Python-list mailing list