Possible to set cpython heap size?

Diez B. Roggisch deets at nospam.web.de
Thu Feb 22 13:19:46 EST 2007


Andy Watson wrote:

>  > Why do you want that? And no, it is not possible. And to be honest:
> I have
>> no idea why e.g. the JVM allows for this.
> 
> The reason why is simply that I know roughly how much memory I'm going
> to need, and cpython seems to be taking a fair amount of time
> extending its heap as I read in content incrementally.

I'm not an expert in python malloc schemes, I know that _some_ things are
heavily optimized, but I'm not aware that it does some clever
self-management of heap in the general case. Which would be complicated in
the presence of arbitrary C extensions anyway.


However, I'm having doubts that your observation is correct. A simple

python -m timeit -n 1 -r 1 "range(50000000)"
1 loops, best of 1: 2.38 sec per loop

will create a python-process of half a gig ram - for a split-second - and I
don't consider 2.38 seconds a fair amount of time for heap allocation.

When I used a 4 times larger argument, my machine began swapping. THEN
things became ugly - but I don't see how preallocation will help there...

Diez



More information about the Python-list mailing list