[Microbit-Python] Micro python: heap memory tuning

Damien George damien.p.george at gmail.com
Mon Sep 19 09:40:34 EDT 2016


You can try adjusting the 9692 value to get more heap.  At some point
you won't be able to link the final firmware because there's not
enough RAM for the requested heap.  The value that's there at the
moment is almost the maximum you can use (unless you remove some other
things that use bss/data).

Using malloc to allocate the heap is not a good idea (there's a small
mbed heap of about 2k but it's needed for the DAL, and hopefully one
day we can reclaim this memory).


On 17 September 2016 at 16:50, Giovanni Giorgi <jj at gioorgi.com> wrote:
> Hi,
>  I am playing with micropython microbit implementation.
> I have removed some modules from the compilation, thus reducing the final
> compiled hex
> I'd like to understand if I can extend the python heap space too.
> I found in mprun.c the following lines:
> ....
>     mp_stack_set_limit(1800); // stack is 2k
>
>     // allocate the heap statically in the bss
>     static uint32_t heap[9692 / 4];
>     gc_init(heap, (uint8_t*)heap + sizeof(heap));
> ....
>
> How can I compute the magic value 9692?
> For instance if I remove some static allocated code, how can I compute a new
> larger value?
> Also the dynamic heap allocation commented how below, is usable or it is a
> "bad idea"?
> ....
>     /*
>     // allocate the heap using system malloc
>     extern void *malloc(int);
>     void *mheap = malloc(2000);
>     gc_init(mheap, (byte*)mheap + 2000);
>     */
>
>
> --
> Giovanni Giorgi
> jj at gioorgi.com
>
>
>
>
>
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list