![Adafruit Feather M4 Express Скачать руководство пользователя страница 74](http://html1.mh-extra.com/html/adafruit/feather-m4-express/feather-m4-express_manual_2845857074.webp)
What is a
MemoryError
?
Memory allocation errors happen when you're trying to store too much on the board. The CircuitPython microcontroller
boards have a limited amount of memory available. You can have about 250 lines of code on the M0 Express boards. If
you try to
import
too many libraries, a combination of large libraries, or run a program with too many lines of code,
your code will fail to run and you will receive a
MemoryError
in the serial console (REPL).
What do I do when I encounter a
MemoryError
?
Try resetting your board. Each time you reset the board, it reallocates the memory. While this is unlikely to resolve your
issue, it's a simple step and is worth trying.
Make sure you are using .mpy versions of libraries. All of the CircuitPython libraries are available in the bundle in a
.mpy format which takes up less memory than .py format. Be sure that you're using
the latest library
bundle
(https://adafru.it/uap)
for your version of CircuitPython.
If that does not resolve your issue, try shortening your code. Shorten comments, remove extraneous or unneeded
code, or any other clean up you can do to shorten your code. If you're using a lot of functions, you could try moving
those into a separate library, creating a
.mpy
of that library, and importing it into your code.
You can turn your entire file into a
.mpy
and
import
that into
code.py
. This means you will be unable to edit your
code live on the board, but it can save you space.
Can the order of my
import
statements affect memory?
It can because the memory gets fragmented differently depending on allocation order and the size of objects. Loading
.mpy
files uses less memory so its recommended to do that for files you aren't editing.
How can I create my own
.mpy
files?
You can make your own
.mpy
versions of files with
mpy-cross
.
You can download the CircuitPython 2.x version of
mpy-cross
for your operating system from the
CircuitPython
Releases page
(https://adafru.it/tBa)
under the latest 2.x version.
You can build
mpy-cross
for CircuitPython 3.x by cloning the
CircuitPython GitHub repo
(https://adafru.it/tB7)
, and
running
make
in the
circuitpython/mpy-cross/
directory. Then run
./mpy-cross path/to/foo.py
to create a
foo.mpy
in the same directory as the original file.
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 79 of 183
Содержание Feather M4 Express
Страница 1: ...Adafruit Feather M4 Express Created by lady ada Last updated on 2019 03 04 10 41 14 PM UTC...
Страница 5: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 10 of 183...
Страница 58: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 63 of 183...
Страница 164: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 169 of 183...
Страница 168: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 173 of 183...