limiting memory consumption of Python itself or a dict in a Python program

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Thu Sep 20 05:10:08 EDT 2007


Jonas Maurus wrote:

> I want to write a Python program that receives messages via SMTP and
> stores them in a dict or an array. For my purposes it would be
> important that all received mail would be kept in RAM and not cached
> out to disk. If a new message comes in that can't fit in the allocated
> memory, a number of old messages would be discarded.
> 
> As the server needs to have room for other tasks, I'd like to limit
> the overall memory consumption to a certain amount.

Since your data is all in one place, why not write a dict or list wrapper
which keeps track of the total space of the items stored (using len on the
strings)?

It could automatically clean out old entries when the memory usage becomes
too much.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list