[Microbit-Python] memory error

David Whale david at thinkingbinaries.com
Fri Oct 2 17:23:47 CEST 2015


I understand from Howard that Joe is working on a persistent memory store
(simulated EEPROM in flash) - could you use that in the future?

Also, did you see my note about AST expansion - do you parse the whole
python source script into a complete explicit AST in RAM and then translate
that into bytecode in RAM, or do you use an implicit 'AST on the machine
stack' style of translation, effectively pipelining AST generation and
bytecode generation? The latter is significantly smaller in terms of RAM
requirements, and scales better regardless of the script complexity.

David.


___________________________________________________________
David Whale, B.Sc (Hons), MIET
*Software Engineer and IET Schools Liaison Officer, Essex*

email:  dwhale at theiet.org
twitter: @whaleygeek
blog:  blog.whaleygeek.co.uk

Co-author of the new book "Adventures in Minecraft" <http://amzn.to/ZGfxZG>
- lets get kids coding!


On 2 October 2015 at 16:07, Damien George <damien.p.george at gmail.com> wrote:

> Hi Alan,
>
> Yes, doc strings do take up memory, so in our case (when trying to
> reduce memory usage) it's better to make them comments (which are just
> skipped over by the tokeniser).
>
> The example you give with lots of prints does indeed take up all the
> memory, so that's why it gives a MemoryError.  It's not easy to fix
> this, the microbit is just really low on RAM!  We could compile the
> python script to flash (instead of RAM) but that needs a bit of effort
> to get working.
>
> Cheers,
> Damien.
>
>
> On Thu, Oct 1, 2015 at 2:52 AM, Alan <alainjackson at hotmail.com> wrote:
> > Hi,
> >
> > Another little trick I've realised is that if I put a large, explanatory
> > comment at the top of the file using """...""" it of course goes into a
> > docstring... which takes up memory!
> >
> > If I use # style comments instead, it doesn't seem to take up memory.
> >
> > Cheers,
> >
> > Alan
> >
> > ________________________________
> > From: alainjackson at hotmail.com
> > To: microbit at python.org
> > Date: Thu, 1 Oct 2015 00:32:14 +0000
> >
> > Subject: Re: [Microbit-Python] memory error
> >
> > Hi,
> >
> > I didn't save the version of my code that got the memory error.
> >
> > But I've just now created a small, pathological example.
> >
> > The code below, which is 3kB on the disk, will create the following
> error:
> >
> >>>> MemoryError:
> > Micro Python v1.4.5-68-g3a2171e on 2015-09-04; micro:bit with nRF51822
> > Type "help()" for more information.
> >
> > But if you delete the last line, it will run fine.
> >
> >
> >
> >
> > """
> > Testing how much memory for python code the microbit has.
> > """
> >
> > from microbit import *
> >
> >
> >
> >
> >
> display.print("123456789022345678903234567890423456789052345678906234567890723456789082345678909234567890")
> >
> display.print("a12345678902234567890323456789042345678905234567890623456789072345678908234567890923456789")
> >
> display.print("ba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345678")
> >
> display.print("cba123456789022345678903234567890423456789052345678906234567890723456789082345678909234567")
> >
> display.print("dcba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("ecba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("fecba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345")
> >
> display.print("gfecba123456789022345678903234567890423456789052345678906234567890723456789082345678909234")
> >
> display.print("hgfecba12345678902234567890323456789042345678905234567890623456789072345678908234567890923")
> >
> display.print("ihgfecba1234567890223456789032345678904234567890523456789062345678907234567890823456789092")
> >
> display.print("123456789022345678903234567890423456789052345678906234567890723456789082345678909234567890")
> >
> display.print("a12345678902234567890323456789042345678905234567890623456789072345678908234567890923456789")
> >
> display.print("ba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345678")
> >
> display.print("cba123456789022345678903234567890423456789052345678906234567890723456789082345678909234567")
> >
> display.print("dcba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("ecba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("fecba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345")
> >
> display.print("gfecba123456789022345678903234567890423456789052345678906234567890723456789082345678909234")
> >
> display.print("hgfecba12345678902234567890323456789042345678905234567890623456789072345678908234567890923")
> >
> display.print("ihgfecba1234567890223456789032345678904234567890523456789062345678907234567890823456789092")
> >
> display.print("123456789022345678903234567890423456789052345678906234567890723456789082345678909234567890")
> >
> display.print("a12345678902234567890323456789042345678905234567890623456789072345678908234567890923456789")
> >
> display.print("ba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345678")
> >
> display.print("cba123456789022345678903234567890423456789052345678906234567890723456789082345678909234567")
> >
> display.print("dcba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("ecba12345678902234567890323456789042345678905234567890623456789072345678908234567890923456")
> >
> display.print("fecba1234567890223456789032345678904234567890523456789062345678907234567890823456789092345")
> >
> >
> >
> >
> >
> >
> >
> >> Date: Wed, 30 Sep 2015 12:01:57 +0100
> >> From: damien.p.george at gmail.com
> >> To: microbit at python.org
> >> Subject: Re: [Microbit-Python] memory error
> >>
> >> Hi Alan,
> >>
> >> Can you post your code?
> >>
> >> On Wed, Sep 30, 2015 at 2:14 AM, Alan <alainjackson at hotmail.com> wrote:
> >> > Hi,
> >> >
> >> > How much memory does the Microbit have for a python program?
> >> >
> >> > I've written a small program about 105 lines long. It's 3kB on my hard
> >> > disk.
> >> > It runs ok now but when it was 115 lines long and 3.2kB I kept getting
> >> > memory allocation errors as soon as I pressed the reset button. If I
> >> > commented about 10 lines out of my program it would run and it didn't
> >> > seem
> >> > to matter which 10 lines. So I assumed it was out of program memory?
> >> >
> >> > Cheers,
> >> >
> >> > Alan
> >> >
> >> > _______________________________________________
> >> > Microbit mailing list
> >> > Microbit at python.org
> >> > https://mail.python.org/mailman/listinfo/microbit
> >> >
> >> _______________________________________________
> >> Microbit mailing list
> >> Microbit at python.org
> >> https://mail.python.org/mailman/listinfo/microbit
> >
> > _______________________________________________ Microbit mailing list
> > Microbit at python.org https://mail.python.org/mailman/listinfo/microbit
> >
> > _______________________________________________
> > Microbit mailing list
> > Microbit at python.org
> > https://mail.python.org/mailman/listinfo/microbit
> >
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/mailman/private/microbit/attachments/20151002/a7e3910c/attachment-0001.html>


More information about the Microbit mailing list