Closed microbit-carlos closed 6 years ago
I have tested the code in 3 versions of MicroPython, nothing attached to the micro:bit:
Traceback (most recent call last):
File "__main__", line 16, in <module>
MemoryError: memory allocation failed, allocating 2816 bytes
Traceback (most recent call last):
File "__main__", line 16, in <module>
MemoryError: memory allocation failed, allocating 3840 bytes
I can confirm that with Mu v0.9.13 the 7-seg script works, but with v1.0.0-rc.1 it doesn't.
Unfortunately I don't think it can be fixed. v1.0.0-rc.1 has about 350 bytes more heap than v0.9.13, so the issue would very likely be memory fragmentation. In v0.9.13 I guess there just happened to be a large enough memory block free due to the pattern of allocations, and in v1.0.0-rc.1 the pattern of allocations has changed and there is no longer a region available.
But I think there's a bug in the 7 segment code that leads to this MemoryError: line 16 is allocating very large bytearray's, each time around the loop it allocates an array (256 i) big, where i goes in the range 0 to 15 inclusive. I think this is a mistake and it should be allocating just two bytes with the given value (256 i). Fixing that would definitely make the script work on v1.0.0-rc.1.
Thanks. I'll take a look at that loop.
Fixed by #539
From: https://github.com/mu-editor/mu/issues/565
Thank you @SteveJSmythe for the testing and reporting the issue!