Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5166

MicroPython • Re: Unable to allocate memory on a raspberry pico w

$
0
0
I tried reserving it in boot.py but now something very strange seems to be happening. My program does not get to run and I get the following memory allocation error:

Code:

MemoryError: memory allocation failed, allocating 342 byte
That to me points to compilation and code generation of 'main.py' pushing things to the limit, over the limit having reserved 32KB.
Doesn't "max free sz: 2306" mean the largest free memory chunk is 2306 bytes?
I am not convinced it does, as on my RP235X ...

Code:

>>> micropython.mem_info(1)stack: 564 out of 7936GC: total: 205568, used: 7456, free: 198112 No. of 1-blocks: 67, 2-blocks: 16, max blk sz: 72, max free sz: 12370...>>> ba = bytearray(65536)>>> micropython.mem_info(1)stack: 564 out of 7936GC: total: 205568, used: 73360, free: 132208 No. of 1-blocks: 79, 2-blocks: 20, max blk sz: 4096, max free sz: 8251
So, for me, it seems 'max free sz' is the number of 16 byte blocks or something like that.
How does it fail to allocate 342? Furthermore there are 121kb of free memory, surely there must be a 342b free chunk..?
I would guess it couldn't allocate 342 at the time, that failure caused scope to be exited all the way back to the REPL which probably freed stuff on the heap on the way down.
Even more, the memory map (or whatever it is) ends with the following:

Code:

1f800: ======..........................................................       (35 lines all free)28800: ........
which means that addresses from 0x1f800 to 0x28800 are free, which is like 36kb?
Possibly. Did you try creating a 32KB byte array at that point ? My guess is it will work.

But, given that it won't compile with 32KB allocated in 'boot.py', I suspect you may have hit the limit of what can be supported by what you have. You may need a redesign which involves doing things other than using a monolithic 'main.py'.

But I also agree having 100KB+ free but not being able to allocate 32KB seems odd. You may have to talk to MicroPython about that or figure out what the 'mem_info(1)' report means and shows.

Statistics: Posted by hippy — Wed Jan 15, 2025 11:56 pm



Viewing all articles
Browse latest Browse all 5166

Trending Articles