Python for embedded systems with memory constraints

MRAB google at
Sun Jun 10 01:02:28 CEST 2007

On Jun 9, 1:33 pm, vishnu <gkkvis... at> wrote:
> Hi,
> Thanks Cameron for your suggestions.
> In fact I am using custom memory sub-allocator where I preallocate a
> pool of memory during initialization of my application and ensure that
> Python doesn't make any system mallocs later . With this arrangement,
> python seems to run out of preallocated memory (of 10MB) after running
> few simple scripts due to huge external fragmentation. My memory
> sub-allocator got a good design which uses the best-fit algorithm and
> coaelescing the adjacent blocks during each free call.
> If anybody out there used their own memory manager and ran Python
> without fragmentation , could provide some inputs on this.
>From what I remember, the best-fit algorithm isn't a good idea because
unless the free block was exactly the right size you'd tend to get
left with lots of small fragments. (Suppose that the best fit was a
free block only 4 bytes bigger than what you want; what can you do
with a free block of 4 bytes?)

A worst-fit algorithm would leave larger free blocks which are more
useful subsequently, but I think that the recommendation was next-fit
(ie use the first free block that's big enough, starting from where
you found the last one).

More information about the Python-list mailing list