how to store great array?

Thomas Wouters thomas at xs4all.net
Tue Jan 30 08:22:06 EST 2001


On Tue, Jan 30, 2001 at 03:14:35AM +0000, Jeff Epler wrote:

> There isn't a portable routine to get the amount of free memory, but
> Python will raise an exception (MemoryError?) in case you allocate all
> available memory.

This is not really true. Python will raise MemoryError if a malloc() call
fails. However, on most modern UNIX systems, malloc() will happily give you
money it doesn't really have, in the assumption you won't really use it
right away, at least not all of it, and that it'll have time to free money
when you do need it. Oops, did I say money ? I meant memory.

Some versions of Linux (like the 2.1.x development kernels, IIRC) actually
froze up if you tried to use (not allocate, but use) more memory than the
machine had available, running in a tight loop to free up memory when there
wasn't anything to be freed up. More sane kernels of Linux, and other OSes,
will probably just generate a segmentation fault or kill off the process or
some such. All in all, not something to do just to find out what the upper
limit of available memory is. You basically just want to use whatever memory
you need, and document that 'MemoryError', 'segmentation violation/fault'
and 'killed' mean that the machine hasn't got the memory it needs :)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list