[Pythonmac-SIG] memory size for Python applets?

Jack Jansen Jack.Jansen@cwi.nl
Mon, 13 Jul 1998 11:08:42 +0200


> Is there any other method than trial and error to determine or at least
> estimate the memory size required for a Python Applet?
> 
> The memory size for the Python interpreter itself is set to around 1.5 MB
> 'minimum' and almost 8 MB (!) 'preferred'. This seems a LOT to me.

The best way to get a good estimate is to run the applet with option pressed 
during startup, select "interactive mode after script", and when you get the 
interactive prompt return to the finder to use the "About this macintosh" box 
to see how much memory is in use.

Python will almost immedeately eat around 1Mb of memory for it's (C) variables 
and the various modules that are loaded during startup (exception.py and 
such), so the 1.5Mb minimum is probably indeed the absolute minimum.

> A simple example applet like the imagebrowser requires more than 4 MB to
> open and display a .jpg.file of less than 100 kB. Is this normal?

That sounds like a bit much. Using imgbrowse (from Mac:Demo:imgbrowse) I have 
a footprint of about 2Mb after opening a single file.

> My Mac does have enough memory for this, but I would like to use Python to
> write small scripts and applets. Several MB imho is a little bit too much
> just for a script with a trivial UI (a preferences dialog box) that does
> trivial things like watching folders, starting apps, working with files,
> sending applescript command and the like.

MacPython isn't optimized for memory usage, on the contrary. In a lot of 
places I've taken the view that memory is cheap, and that if cycles can be 
gained by wasting memory that is fine. The memory allocator is an example of 
this: it allocates blocks in power-of-two sizes, resulting in a loss of about 
25% extra memory, but resulting in a speedup that can be as much as 10% in 
normal cases (and much higer even in long-running processes, due to 
pathological behaviour of the realloc() in the standard MetroWerks library). 
All memory is also allocated cache-aligned, resulting in a further performance 
gain (especially on 604 processors) but wasting more memory.

Also, something you shouldn't forget is that with Python you see the _real_ 
memory use in the application. With things like AppleScript there's a lot of 
memory used that is allocated from the system heap, so it looks as thought the 
applet doesn't use much memory, but in fact it does, only it allocates it in a 
different place.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl      | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm